我想用TouchSwipe绑定DOM元素上的多个滑动事件。 demo没有包含多个事件的示例。我尝试了以下内容:
$("#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
});
但不幸的是,只有第一个事件发生(见小提琴)。
TouchSwipe库可以实现吗?如果有,怎么样?如果不是,你能推荐一个能够绑定元素上多个事件的库吗?
答案 0 :(得分:0)
您可以使用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'
});
有关详细信息,请参阅:link
答案 1 :(得分:0)
这是我添加多个滑动事件的示例。
$("#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
})