jquery - How to prevent swipe to trigger click? -
i use touchswipe create swipeable image list. bind swipe event images, while bind click event open image's large version.
my problem if swipe, fires click event. tried tap instead of swipe can't make work. after tried event.preventdefault()
, event.stoppropagation()
suggested in lot of place, there no effect. final solution attempt unbind click event , rebind after event, if bind event in end of event function, fires click again.
$(".js-header-swipe-image").swipe({ swipe:function(event, direction, distance, duration, fingercount){ $("#details").unbind('click');//temporary unbind, otherwise swipe's click trigger gallery opening. //handling swipe direction. $('#details').on('click', '.js-header-swipe-image', function (){//rebind temporary unbinded event. console.log('click'); $('#modal-gallery').modal('show'); }); } });
is there way abort event or call function after event finished can rebind click after swipe finished wouldn't trigger rebinded click? i'm open other solution problem.
i use bit of code buttons triggered (on touchend) if not being swiped on:
var starty; var ydistance; function touchhandler(event) { touch = event.changedtouches[0]; event.preventdefault(); } $('.button').on("touchstart", touchhandler, true); $('.button').on("touchmove", touchhandler, true); $('.button').on("touchstart", function(){ starty = touch.clienty; }); $('.button').on('touchend', function(){ ydistance = starty - touch.clienty; if(math.abs(ydist) < 30){ //button response here, if user not swiping console.log("button pressed") } });
Comments
Post a Comment