我有一个非常简单的用例。jquery手机向左滑动两次
在页面init加载一个html。
$(document).on('pageinit',function(){
window.localStorage.setItem("page",'intro_1');
$('#navigation_main').load('html/intro_1.html');
});
在滑动只是改变dom。
var flag = 0;
$("body").bind("swipeleft",function(event) {
flag +=1;
page = window.localStorage.getItem("page");
alert(flag);
switch(page){
case 'intro_1':
window.localStorage.setItem("page",'intro_2');
$('#navigation_main').load('html/intro_2.html');
break;
case 'intro_2':
window.localStorage.setItem("page",'challenges');
$('#navigation_main').load('html/challenges.html');
break;
case 'challenges':
window.localStorage.setItem("page",'risk_areas');
$('#navigation_main').load('html/risk_areas.html');
break;
default:
window.localStorage.setItem("page",'intro_1');
$('#navigation_main').load('html/intro_1.html');
break;
}
});
现在这个向左滑动触发两次,导致后续页面被加载。我怎样才能阻止呢?
其仍然发射两次 –
必须绑定两次尝试$(“body”)。die(“swipeleft”,<把你的函数放在这里>);以杀死第一个绑定项目,然后添加它。 –
这个答案是旧的,但你的意思是$(“body”)。on'。这是“开始”,而不是“一个”。 – BrettFromLA