我正在使用带有触摸支持的Jquery事件监听器构建混合移动应用程序来创建交互但是我遇到了调用使用.animate
的函数的事件侦听器的问题。第一个animate
工作正常,但第二次更慢,第三次更慢。看一下日志,似乎事件监听器每次调用时都会将对函数的调用乘以2。
我已经将问题缩小到事件监听器,因为当在chrome dev工具中手动调用时,函数可以完美地工作。我尝试过使用jquery .on
和.one
事件监听器。下面是我的代码,很高兴就此得到一些建议...
HTML
<div id="closeIcon"></div>
和JS ......
$('#closeIcon').one("tap", closeLogin);
function closeLogin(){
$('#userContainer').animate({'padding-top': '120px'}, 500);
$('#contentContainer').animate({'height': '682px'}, 500, function(){
unselectUser();
$('#loginContainer').empty();
$('#loginContainer').css('visibility', "hidden");
});
}
答案 0 :(得分:0)
试试这个:
$('#closeIcon').one("tap", closeLogin);
function closeLogin(e){
e.stopImmediatePropagation();
$('#userContainer').animate({'padding-top': '120px'}, 500);
$('#contentContainer').animate({'height': '682px'}, 500, function(){
unselectUser();
$('#loginContainer').empty();
$('#loginContainer').css('visibility', "hidden");
});
}