我有一个问题,即一个避免双重事件jQuery的停止双重事件
所以开始与我有一段代码触发
jQuery(window).trigger('swipeForward');
所以这个监听这个触发
jQuery(window).on('swipeForward', swipeHandlerNext);
滑动处理程序的想法是,使用户不能滑动两次并创建双重事件
这将然后执行swipeHandlerNext功能
function swipeHandlerNext(event) {
// If event isn't already marked as handled, handle it
if(event.handled !== true) {
// Kill event handler, preventing any more clicks
jQuery(".pageSize").off("swipeForward");
// Do your stuff here
pageSize = jQuery(".mainHeader").width();
slide("forward", pageSize);
console.log(" swipe complete page forward via swipe");
// Mark event as handled
event.handled = true;
}
return false;
}
这显然执行滑动功能。这是一个有.animate命令
function slide(data, pageSize) {
if (!pageSize) {
pageSize = jQuery(".mainHeader").width();
}
var promise = calcLeft(data, pageSize);
jQuery.when(promise).then(function(result) {
console.log(result);
jQuery('#pageHolder').delay(500).animate({
left: result
}, 400, function() {
console.log("animation started");
calcNav(pageSize);
calcPage(pageSize);
jQuery(".pageSize").on("swipeForward", swipeHandlerNext);
console.log("animation complete");
});
});
}
然而,它不是防止双重幻灯片。
感谢所有帮助
嗨..谢谢..这个问题真的源于这里.. http://stackoverflow.com/questions/14996012/jquery-animate-periodocially-not-running任何想法?我拉我的头发 – Dan 2013-02-22 00:56:47
@丹整体来说,它似乎是同一个问题。用当前问题中描述的问题的可能解决方案更新了我的答案。看看这些是否有帮助。 – Boaz 2013-02-22 01:02:56
嗨 - 我现在正在所有的地方使用窗口。是的,我在那里很厚。它不能在某个时间工作的原因虽然很奇怪。这可能与我的刷卡代码有关吗?看到我使用功能幻灯片两个刷卡事件和点击。我真的没有得到它是如何工作的,有时候并不是 - 特别是当事件被排序时 – Dan 2013-02-22 01:05:42