我正在try 向元素添加一个简单的左/右滑动事件.在滑动时,应该执行一些jQuery.我已经try 了许多脚本来实现这一点,但都没有成功.
现在我用的是这个:https://gianlucaguarini.com/Tocca.js/
我可以在onClick中使用相同的代码,它可以工作,所以我不明白为什么它不能在Swipe上工作.
可以使用以下内容重现此问题:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
</head>
<body>
<div id="test-swipe" style="background-color: red; min-height: 200px;"></div>
<a id="test-click" href="https://google.com">link</a>
<br ><br >
<a id="manual-trigger" href="https://google.com">manually trigger the click</a>
<script>
// On Swipe Left
$("#test-swipe").on('swipeleft',function (e,data){
console.log(data.x);
console.log(data.y);
console.log(data.distance.x);
console.log(data.distance.y);
$("#test-click").click();
});
</script>
<script>
// On Manual Click
$( "#manual-trigger" ).on( "click", function() {
$("#test-click").click();
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Tocca.js/2.0.9/Tocca.min.js"></script>
</body>
</html>