vue-uniapp-滑动处理

24 篇文章 2 订阅

代码如下

<view
            v-for="(item,index1) in dataList"
            :key="index1"
            :class=" (item.pxxh %2 ==0) ? itemContent1:itemContent"
            @touchmove="handletouchmove"
            @touchstart="handletouchstart"
            @touchend="deleteShow(index1)"
        >


data () {
        return {
            rowMoveCtrl: {
                flag: 0,
                text: '没有滑动',
                lastX: 0,
                lastY: 0
            },

        handletouchstart (event){
            this.rowMoveCtrl.lastX = event.touches[0].pageX
            this.rowMoveCtrl.lastY = event.touches[0].pageY
        },
        handletouchmove (event){
            if(this.rowMoveCtrl.flag !== 0){
                return
            }
            let curX = event.touches[0].pageX
            let curY = event.touches[0].pageY
            let difX = curX - this.rowMoveCtrl.lastX
            let difY = curY - this.rowMoveCtrl.lastY
            let text = ''
            // 左右方向滑动判断
            if(Math.abs(difX) > Math.abs(difY)){
                if(difX < 0){
                    text = '向左滑动'
                    this.rowMoveCtrl.flag = 1
                } else if(difX > 0){
                    text = '向右滑动'
                    this.rowMoveCtrl.flag = 2
                }
            } else {
                // 上下方向滑动判断
                if(ty < 0){
                    text = '向上滑动'
                    this.rowMoveCtrl.flag = 3
                }else if(ty > 0){
                    text = '向下滑动'
                    this.rowMoveCtrl.flag = 4
                }
            }
            this.rowMoveCtrl.lastX = curX
            this.rowMoveCtrl.lastY = curY
            this.rowMoveCtrl.text = text
        },
        deleteShow (curIndex){
            if(this.rowMoveCtrl.flag === 0){
                return
            } else if(this.rowMoveCtrl.flag === 2){
                // 向右滑动
                this.bdelete[curIndex].visible = true
            }
            this.rowMoveCtrl.flag = 0
            this.rowMoveCtrl.text = '没有滑动'
            
        },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Listest

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值