【发布时间】:2012-05-10 18:52:09
【问题描述】:
我这里有这个功能
$(document).keydown(function(e){
if (e.which == 39) {
goRight();
}
if (e.which == 37) {
goLeft();
};
});
我想要这样:如果我按下右或左箭头键,调用我的任何功能(goRight 或 goLeft),我只能在该功能完成后执行其他按键操作。我想要的类似于动画的 stop() 函数。因为当我快速按左/右时,我的所有边距都会被窃听。
goRight 函数是这样的
function goRight(){
if(!$('.livin').hasClass('blog') ){
$('#contentGeral .containerConteudo ul').stop().animate({marginLeft:'-=800'},function(){
removeClasses();
addClasses();
});
}
else{
$('#contentGeral .containerConteudo ul').stop().animate({marginLeft:'0'}, function(){
removeClasses();
addClasses();
});
}
}
goLeft 是类似的。
提前感谢您的帮助!
【问题讨论】:
-
你有没有在函数中尝试
.stop(true,true) -
在动画函数中或者像“e.stop(true,true).which”甚至像这样的“stop(true,true).goLeft();” ?
-
没关系,动画中的 stop(true,true) 成功了!谢谢!