How can I stop clicking on a link from firing when using jQuery touch swipe?
-
Markup
<div id="banner-top" class="banner"> <a href="/sdc/"><img src="/i/banner.jpg" /></a> </div>
Handler
// библиотека jquey + https://github.com/mattbryson/TouchSwipe-Jquery-Plugin $("#banner-top").swipe( { swipe:function(event, direction, distance, duration, fingerCount, fingerData) { //event.preventDefault(); // не работает //console.log(event); // пусто... console.log("You swiped " + direction); alert('stop'); } });
I put a handler on # banner-top, but inside it is the [a] tag on which the click event is triggered.
How can I cancel a click event on a link?JavaScript Felicity McMahon, Nov 23, 2020 -
I asked myself, I answered myself))
$(function() {
$("#banner-top").swipe( {
swipe:function(event, direction, distance, duration, fingerCount, fingerData) {
console.log("You swiped " + direction);
// проблема только для декстопа
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) == false)
{
event.target.onclick = function(e) {
e.preventDefault();
this.onclick = false;
}
}
}
});
});Anonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!