首页 > 移动平台 > 详细

uniapp 上下左右手势滑动时的事件

时间:2021-06-18 23:44:57      阅读:194      评论:0      收藏:0      [点我收藏+]
<template>  
    <view @touchstart="touchStart" @touchend="touchEnd" style="height:2000px;">  
        测试  
    </view>  
</template>  
<script>  
    export default {  
        data() {  
            return {  
                touchStartX: 0,  // 触屏起始点x  
                touchStartY: 0,  // 触屏起始点y  
            };  
        },  
        methods: {  
            /**  
            * 触摸开始  
            **/  
            touchStart(e) {  
                console.log("触摸开始")  
                this.touchStartX = e.touches[0].clientX;  
                this.touchStartY = e.touches[0].clientY;  
            },  

            /**  
            * 触摸结束  
            **/  
            touchEnd(e) {  
                console.log("触摸结束")  
                let deltaX = e.changedTouches[0].clientX - this.touchStartX;  
                let deltaY = e.changedTouches[0].clientY - this.touchStartY;  
                if (Math.abs(deltaX) > 50 && Math.abs(deltaX) > Math.abs(deltaY)) {  
                    if (deltaX >= 0) {  
                        console.log("左滑")  
                    } else {  
                        console.log("右滑")  
                    }  
                } else if(Math.abs(deltaY) > 50&& Math.abs(deltaX) < Math.abs(deltaY)) {  
                    if (deltaY < 0) {  
                        console.log("上滑")  
                    } else {  
                        console.log("下滑")  
                    }  
                } else {  
                    console.log("可能是误触!")  
                }  
            },            
        }  
    };  
</script>

转于:https://ask.dcloud.net.cn/article/38074

uniapp 上下左右手势滑动时的事件

原文:https://www.cnblogs.com/chenshaoxiong/p/14900854.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!