其它都是正常的,就是拉上去拉下来自己又回弹回去了,拉不到最底部也拉不到最顶部,拉来拉去都会是这样的

category/index.vue

import CategoryHeader from "./header";

import CategoryTab from "./tab";

import CategoryContent from "./content";

export default {

name: "Category",

components: {

CategoryHeader,

CategoryTab,

CategoryContent

},

data(){

return{

curId: ''

}

},

methods:{

getCurrentId(id){

this.curId = id;

}

}

};

@import "~assets/scss/mixins";

.category{

overflow: hidden;

width:100%;

height:100%;

background-color:$bgc-theme;

}

.g-content-container{

display:flex;

}

.sidebar{

width: 80px;

height:100%;

}

.main{

flex:1;

height:100%;

}

tab.vue

  • class="tab-item"

    :class="{'tab-item-active': item.id === curId}"

    v-for="(item,index) in items"

    :key="index"

    @click="switchTab(item.id)"

    >{{item.name}}

import MeScroll from 'base/scroll';

import {categoryNames} from './config';

export default {

name:'CategoryTab',

components: {

MeScroll

},

data() {

return {

curId:''

};

},

// 因为数据只需要赋值一次,所以就把数据写在methods的init()里

created(){

this.init();

this.switchTab(this.items[0].id);

},

methods:{

init(){

this.items=categoryNames;

},

switchTab(id){

if(this.curId === id){

return;

}

this.curId = id;

this.$emit('switch-tab',id)

}

}

};

@import "~assets/scss/mixins";

$tab-item-height: 46px;

.tab {

width: 100%;

&-item {

height: $tab-item-height;

background-color: #fff;

border-right: 1px solid $border-color;

border-bottom: 1px solid $border-color;

color: #080808;

font-size: $font-size-l;

font-weight: bold;

text-align: center;

line-height: $tab-item-height;

@include ellipsis();

&:last-child {

border-bottom: none;

}

&-active {

background: none;

border-right: none;

color: #f23030;

}

}

}

base/scroll/index.vue

// 滚动条也是使用swiper插件

import { swiper, swiperSlide } from "vue-awesome-swiper";

import MeLoading from "base/loading";

import {

PULL_DOWN_HEIGHT,

PULL_DOWN_TEXT_INIT,

PULL_DOWN_TEXT_START,

PULL_DOWN_TEXT_ING,

PULL_DOWN_TEXT_END,

PULL_UP_HEIGHT,

PULL_UP_TEXT_INIT,

PULL_UP_TEXT_START,

PULL_UP_TEXT_ING,

PULL_UP_TEXT_END

} from "./config";

export default {

components: {

swiper,

swiperSlide,

MeLoading

},

props: {

scrollbar: {

type: Boolean,

default: true

},

//这个data是接收

data: {

type: [Array, Object]

},

pullDown: {

type: Boolean,

default: false

},

pullUp: {

type: Boolean,

default: false

}

},

watch: {

data() {

this.update();

}

},

created(){

this.init();

},

methods: {

update() {

// 外部调用的api

//如果它存在的话再调用swiper下面的update()

this.$refs.swiper && this.$refs.swiper.swiper.update();

},

scrollToTop(speed,runCallbacks) {

// 不是什么回到顶部,而是返回到第一个幻灯片

this.$refs.swiper && this.$refs.swiper.swiper.slideTo(0,speed,runCallbacks)

},

init(){

this.pulling= false;

this.pullDownText= PULL_DOWN_TEXT_INIT;

this.pullUpText= PULL_UP_TEXT_INIT;

this.swiperOption= {

direction: "vertical",

slidesPerView: "auto", //一页能看几张图片,auto是自适应

freeMode: true, //如果设置了这个大力滑可以滑很远

setWrapperSize: true, //自动给sliderwrapper设置高度

scrollbar: {

el: this.scrollbar ? ".swiper-scrollbar" : null,

hide: true //是否自动隐藏

},

on: {

sliderMove: this.scroll,

touchEnd: this.touchEnd,

transitionEnd:this.scrollEnd

}

}

},

// 内部自己使用的

scroll() {

//this.$refs.swiper是通过refs找到这个组件,

//后面的.swiper就是找到它组件的对象,swiper里又很多的属性

const swiper = this.$refs.swiper.swiper;

// 传什么时候显示返回顶部按钮,什么时候隐藏

this.$emit('scroll',swiper.translate,this.$refs.swiper.swiper);

if (this.pulling) {

return;

}

if (swiper.translate > 0) {

//大于0就是下拉

if (!this.pullDown) {

return;

}

if (swiper.translate > PULL_DOWN_HEIGHT) {

this.$refs.pullDownLoading.setText(PULL_DOWN_TEXT_START);

} else {

this.$refs.pullDownLoading.setText(PULL_DOWN_TEXT_INIT);

}

} //下拉

//判断是否到达底部

else if (swiper.isEnd) {

if (!this.pullUp) {

return;

}

const isPullUp =

Math.abs(swiper.translate) + swiper.height - PULL_UP_HEIGHT >

parseInt(swiper.$wrapperEl.css("height")); //判断是否到达上拉的触发条件,//abs的意思是绝对值

if (isPullUp) {

this.$refs.pullUpLoading.setText(PULL_UP_TEXT_START);

} else {

this.$refs.pullUpLoading.setText(PULL_UP_TEXT_INIT);

}

}

},

//滑动停止后触发的事件

scrollEnd(){

this.$emit('scroll-end',this.$refs.swiper.swiper.translate,this.$refs.swiper.swiper,this.pulling);

},

touchEnd() {

if (this.pulling) {

return;

}

const swiper = this.$refs.swiper.swiper;

if (swiper.translate > PULL_DOWN_HEIGHT) {//下拉

if (!this.pullDown) {

return;

}

this.pulling = true;

swiper.allowTouchMove = false; //正在加载时禁止触摸

swiper.setTransition(swiper.params.speed); //通过参数找到初始的速度

swiper.setTranslate(PULL_DOWN_HEIGHT); //拖过头了就移动到100的位置

swiper.params.virtualTranslate = true; //定住不给回弹

this.$refs.pullDownLoading.setText(PULL_DOWN_TEXT_ING);

this.$emit("pull-down", this.pullDownEnd);

}

//上拉,判断是否到底部

else if(swiper.isEnd){

const totalHeight = parseInt(swiper.$wrapperEl.css('height'));

const isPullUp =  Math.abs(swiper.translate) + swiper.height - PULL_UP_HEIGHT >

totalHeight; //判断是否满足触发的条件

if(isPullUp){//上拉

if(!this.pullUp){

return;

}

this.pulling = true;//正在加载中,不能够继续加载

swiper.allowTouchMove = false;//禁止触摸

swiper.setTranslate(-(totalHeight + PULL_UP_HEIGHT - swiper.height));

swiper.params.virtualTranslate = true;//定住不给回弹

this.$refs.pullUpLoading.setText(PULL_UP_TEXT_ING);

this.$emit('pull-up',this.pullUpEnd);

}

}

},

pullDownEnd() {

//下拉后恢复原值

const swiper = this.$refs.swiper.swiper;

this.pulling = false;

this.$refs.pullDownLoading.setText(PULL_DOWN_TEXT_END);

swiper.params.virtualTranslate = false; //开始可以回弹

swiper.allowTouchMove = true; //可以触摸

swiper.setTransition(swiper.params.speed);

swiper.setTranslate(0); //回到0的位置

console.log(swiper.params)

// 下拉回弹后显示header

setTimeout(() =>{

this.$emit('pull-down-transition-end');

},swiper.params.speed);

},

pullUpEnd(){

//上拉后恢复原值

const swiper = this.$refs.swiper.swiper;

this.pulling = false;

this.$refs.pullUpLoading.setText(PULL_UP_TEXT_END);

swiper.params.virtualTranslate = false;//开始可以回弹

swiper.allowTouchMove = true;

}

}

};

.swiper-container {

overflow: hidden;

width: 100%;

height: 100%;

}

.swiper-slide {

height: auto;

}

.mine-scroll-pull-up,

.mine-scroll-pull-down {

position: absolute;

left: 0;

width: 100%;

}

.mine-scroll-pull-down {

bottom: 100%;

height: 80px;

}

.mine-scroll-pull-up {

top: 100%;

height: 30px;

}

swiper怎么让不会回弹,为什么我的滚动条拉上拉下都会回弹呢?相关推荐

  1. android rebound平移,Android 仿 IOS 拖拽回弹之进阶 ReboundFrameLayout

    Android 仿 IOS 拖拽回弹之进阶 ReboundFrameLayout 前言 IOS 拖拽回弹给用户的体验不得不赞然后 Android 原生的 API 各种不支持, 于是乎出现的很多仿 IO ...

  2. 返回内容验签失败_邮件经常失败回弹很糟心?一定要知道这几个小知识

    很多人都反应每次发送邮件,总有一部分发生失败回弹,大大影响了送达率,非常糟心! 今天我们为大家整理了一些常见关于发送回弹状态的相关知识以及如何避免邮件回弹的注意事项. 一.回弹状态的两种类型 邮件发送 ...

  3. 折弯弹性计算公式_冲压模具:影响回弹因素、回弹计算公式计算,值得收藏

    回弹,设计师都会遇到,而且无法避免,只能想办法补偿或者降低影响.那什么是回弹呢? 金属材料在塑性弯曲时总是伴随著弹性变形,因此当弯矩去掉之后,弯曲件的弯曲半径变得与模具尺寸不一致,这种现象称为回弹.而 ...

  4. swiper 上滑触发_新知 | 为何红酒杯壁挂“眼泪”,骑自行车不会倒,冰面那么滑?...

    pixabay.com 撰文 | 二宗主 图片 | 岳   岳 ●         ●         ● 无论是宇宙深处神秘的黑洞的样子,还是微观世界中的亚原子粒子的行为,科学家已经解锁了许多我们甚 ...

  5. 获得邮件列表失败_邮件经常失败回弹很糟心?一定要知道这几个小知识

    很多人都反应每次发送邮件,总有一部分发生失败回弹,大大影响了送达率,非常糟心! 今天我们为大家整理了一些常见关于发送回弹状态的相关知识以及如何避免邮件回弹的注意事项. 一.回弹状态的两种类型 邮件发送 ...

  6. 冲压模具中的回弹解决办法

    对于各类冲压件来说,拉深模是最不好处理的,因为材料会产生流动,其它的类型,会处理一些,但像尺寸要求高的冲压件,回弹的问题有时候也是非常头痛的,目前部落还没有看到哪里有准备的回弹计算公式,一般都是大家凭 ...

  7. 邮件经常失败回弹很糟心?一定要知道这几个小知识

    很多人都反应每次发送邮件,总有一部分发生失败回弹,大大影响了送达率,非常糟心! 今天我们为大家整理了一些常见关于发送回弹状态的相关知识以及如何避免邮件回弹的注意事项. 一.回弹状态的两种类型 邮件发送 ...

  8. swiper轮播图切换指示点改变背景颜色

    swiper 官方api文档:https://www.swiper.com.cn/api/index.html 如果有一个页面中需要引用多个Swiper,可以给每个容器加上ID或Class区分,但是需 ...

  9. Android webView 实现阻尼回弹效果

    iOS webView默认滑动到顶部或者底部的时候,还可以继续通过手指拉扯滑动,松手后回弹:而Android webView默认是不行的,要实现跟iOS一样的效果,就需要自定义webView. ios ...

最新文章

  1. 洛谷 P1865 A % B Problem[筛素数/前缀和思想/区间质数个数]
  2. vim简单使用教程【转】
  3. Spring Boot+Vue从零开始搭建系统(一):项目前端_Vuejs环境搭建
  4. 以太坊发token教程
  5. EOS账户系统(4)账户权限分级
  6. HashMap的7种遍历方式
  7. html + css + js 实现简易计算器
  8. java json插件安装_IDEAL葵花宝典:java代码开发规范插件:GsonFormat插件将JSONObject格式的String 解析成实体...
  9. endnote大客户版_Endnote软件的使用,有图有干货!
  10. android背景颜色动态修改,Android自定义TextView带圆角及背景颜色(动态改变圆角背景颜色)...
  11. Windows 2008 R2 导出Excel时提示:未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序。
  12. oracle11g安装副武器类,oracle 11g 服务器类
  13. 傅立叶变换、拉普拉斯变换、Z 变换的联系是什么?为什么要进行这些变换?...
  14. 1.checkpoint防火墙安装以及高可靠性配置
  15. 2019辽宁公务员考试行测常识大全:公务员常识40000问(五十九)(2)
  16. 摘抄“GPU Programming And Cg Language Primer 1rd Edition” 中文 名“GPU编程与CG语言之阳春白雪下里巴人”
  17. IBM沃森对哈利波特各大主角的人格分析
  18. 用计算机算出别人多少岁,年龄计算器 年龄计算器查询
  19. What does assigning ‘shift‘ to a variable mean?
  20. APK获取包名的办法

热门文章

  1. matlab最优控制实验报告_第十二篇 章 用MATLAB解最优控制问题及应用实例 最优控制课件.ppt...
  2. 在线html差错,易查分在线编辑功能:发现错误随时修改,不用再重新上传表格!
  3. mac 使用 php artisan,在Mac php artisan上設置Laravel遷移錯誤:沒有這樣的文件或目錄[duplicate]...
  4. 875. 爱吃香蕉的珂珂(二分)
  5. linux退出大于符号,每天一个linux命令--退出符号
  6. u6系统服务器启动不了,u6链接不到服务器
  7. 2008服务器系统功能,Windows Server 2008 DNS服务器新增功能
  8. 计算机技术分,计算机技术专业那么多,你分得清吗?
  9. 软件工程--第三章--需求分析
  10. 计算机控制技术与自动化的关系,计算机控制技术东南大学自动化学院.ppt