使用TouchSwipe在元素上进行多次滑动事件

我想用TouchSwipe绑定DOM元素上的多个滑动事件。 该演示没有多个事件的示例。 我尝试了以下内容:

$("#test").swipe( { //Generic swipe handler for all directions swipeRight:function(event, direction, distance, duration, fingerCount) { alert("you swiped " + direction); }, //Default is 75px, set to 0 for demo so any distance triggers swipe threshold:10 }); $("#test").swipe( { //Generic swipe handler for all directions swipeLeft:function(event, direction, distance, duration, fingerCount) { alert("you swiped " + direction); }, //Default is 75px, set to 0 for demo so any distance triggers swipe threshold:10 }); 

http://jsfiddle.net/xktJ9/

但不幸的是,只有第一次事件发生(见小提琴)。

这可以通过TouchSwipe库实现吗? 如果有,怎么样? 如果不是,你能推荐一个能够绑定元素上多个事件的库吗?

您可以使用touchSwipe的swipeStatus方法代替swipeRight或swipeLeft。

  $("#test").swipe( { swipeStatus:function(event, phase, direction, distance, duration, fingers) { //Here we can check the: //phase : 'start', 'move', 'end', 'cancel' //direction : 'left', 'right', 'up', 'down' //distance : Distance finger is from initial touch point in px //duration : Length of swipe in MS //fingerCount : the number of fingers used if (phase=="end" && (direction == 'left' || direction == 'right')) { alert("you swiped " + direction); } }, //Default is 75px, set to 0 for demo so any distance triggers swipe threshold:10, maxTimeThreshold:5000, fingers:'all' }); 

有关详细信息,请参阅: 链接

这是我添加多个滑动事件的示例。

 $("#demo1").swipe( { //Single swipe handler for left swipes swipeRight:function() { demo1.goToPrevSlide(); return false; } , swipeLeft:function() { demo1.goToNextSlide(); return false; },excludedElements:"", allowPageScroll:"vertical", preventDefaultEvents:false })