移动端上下左右滑动事件

浅浅的花香味﹌ 2022-05-15 08:27 390阅读 0赞

注意:要用on方法

$(“.activity_goods”).on(“touchstart”,’.activity_goods_left’,function(e) {
if (e.cancelable) {
if (!e.defaultPrevented) {
e.preventDefault();
}
}
startX = e.originalEvent.changedTouches[0].pageX,
startY = e.originalEvent.changedTouches[0].pageY;
});
$(“.activity_goods”).on(“touchend”, ‘.activity_goods_left’,function(e) {
if (e.cancelable) {
if (!e.defaultPrevented) {
e.preventDefault();
}
}
moveEndX = e.originalEvent.changedTouches[0].pageX,
moveEndY = e.originalEvent.changedTouches[0].pageY,
X = moveEndX - startX,
Y = moveEndY - startY;
// 左滑
if (X<0) \{ let zix = $('.collection2\_delete').width()-5; $(this).css('margin-left',-zix) $(this).siblings('.collection2\_delete').show() \} // 右滑 else if (X>0) {
$(this).css(‘margin-left’,0)
$(this).siblings(‘.collection2_delete’).hide()
}
// 上滑
else if (Y<0) \{return\} // 下滑 else if (Y>0) {return}
// 点击
else{return}
});

发表评论

表情:
评论列表 (有 0 条评论,390人围观)

还没有评论,来说两句吧...

相关阅读

    相关 移动滑动事件方法

    今天使用jquery.fullpage.js的时候,发现移动端调试不支持滑动事件,于是自己写了一个滑动的事件,如下,使用这个插件时只需要给window绑定一个滑动事件就可以了,