手势上滑下滑

<!-- //在最外层用u-transition组件包起来,具体可看官方文档:"https://uniapp.dcloud.io/component/uniui/uni-transition?id=基本用法"; -->
        <uni-transition custom-class="menu_warp" :show="show" ref="menuWarp">

<view class="bar" @touchmove="touchMove" @touchend="touchEnd" @touchstart="touchStart">

</view>

    </uni-transition>

//开始触摸
            touchStart(e) {
                //记录手指触摸到屏幕的那一个的位置,计算小黑条的top值
                this.start = (e.changedTouches[0].pageY / this.windowHeight).toFixed(2);
            },
            //触摸开始并且移动
            touchMove(e) {

                //step 和 run 方法 查看uniapp官方文档:"https://uniapp.dcloud.io/component/uniui/uni-transition?id=基本用法";其实文档上写需要先初始化init,但是不init也可以使用,不知道为什么
                let top =
                    (e.changedTouches[0].pageY / this.windowHeight).toFixed(2) * 100 +
                    "vh";
                //top:e.changedTouches[0].pageY:手指移动的实时位置,计算后转换为滑动层的top值,单位vh;
                // console.log(top);

                

       if (parseInt(top) >= 94) {
                    top = "94vh";
                } else if (parseInt(top) <= 60) {
                    top = "60vh";
                } else {
                    top = top;
                }
                this.$refs.menuWarp.step({
                    top: top
                }, {
                    duration: 180
                });
                this.$refs.menuWarp.run(() => {});

     },
            //手指离开手机
            touchEnd(e) {
                const start = this.start * 100;
                const end =(e.changedTouches[0].pageY / this.windowHeight).toFixed(2) * 100;
                if (start > end) {
                    
                    this.$refs.menuWarp.step({
                        top: "60vh"
                    }, {
                        duration: 180
                    });
                    this.$refs.menuWarp.run(() => {});
                } else if (start < end) {
                    this.$refs.menuWarp.step({
                        top: "94vh"
                    }, {
                        duration: 180
                    });
                    this.$refs.menuWarp.run(() => {});
                }
            },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值