The example in this article describes the jquery method of sliding the photo album twice at once. Share it with everyone for your reference. The specific implementation method is as follows:
var t1=null; //定义为全局变量 $('body').on('touchstart', '#gallerySlider img', function(e){ var touch = e.originalEvent, startX = touch.changedTouches[0].pageX; if (t1 == null){ t1 = new Date().getTime(); }else{ var t2 = new Date().getTime(); if(t2 - t1 < 500){ t1 = t2; return; }else{ t1 = t2; } } slider.on('touchmove',function(e){ event.stopPropagation(); touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0]; if(touch.pageX - startX > 10){ slider.off('touchmove'); showPrevious(); } else if (touch.pageX - startX < -10){ slider.off('touchmove'); showNext(); } }); return false; }).on('touchend',function(){ slider.off('touchmove'); });
Record the time when the finger slide starts, and record the time when it ends. If the two time differences are very close, it ends.
I hope this article will be helpful to everyone’s jQuery programming.