我为PhoneGap应用构建了一个GUI。有很多可滑动的页面可以在应用程序中导航。我使用jQuery插件" touchSwipe"设置滑动处理程序。
当我点击向应用添加新页面的按钮时,页面数量会有所不同。
我的问题是,当我添加新页面时,新页面上的滑动不起作用。当我添加页面时,我只需再次调用该方法,即设置" touchSwipe"处理程序。
$(".page").swipe({
swipeStatus: function(event, phase,
direction, distance, duration,fingerCount) {
CODE HERE
}
});
所以hanlder通过类" page"附加到所有元素。添加的新元素也有这个类。
我想不可能覆盖处理程序?
由于性能问题,我无法将滑动处理程序添加到单个元素。我正在一个小例子脚本中进行测试。
$("#swipeField").swipe({
swipeStatus: function(event, phase, direction, distance, duration, fingerCount) {
$(this).text("You swiped: " + direction);
}
});
$("#unbindSwipeHandler").click(function() {
$("#swipeField").unbind();
});
$("#setSwipeHandler").click(function() {
$("#swipeField").swipe({
swipeStatus: function(event, phase, direction, distance, duration, fingerCount) {
$(this).text("You swiped: " + direction);
}
});
});
我想这个解决方案应该有更好的性能。事情是它只是赢了工作。正如您在打开页面时所看到的那样,滑动处理程序已设置,方向显示在滑动字段中。单击按钮取消绑定后,文本不再更改。但是当我按下" setSwipeHandler"按钮没有任何反应 - 处理程序没有设置。
所以我不能绑定以前的.unbind()元素吗?
答案 0 :(得分:3)
尝试使用destroy
代替unbind
$("#unbindSwipeHandler").click(function() {
$("#swipeField").swipe('destroy');
});