因此,这段代码没有按照我的预期去做,停止什么都不做,它会保持动画效果给出奇怪的结果,(因为newpos的计算是错误的。
if (direction =='left') {
newpos = parseInt(currentpos) - 300;
$('.slider').stop(true, true).animate({"margin-left": newpos}, 1000, "easeOutQuart");
}
else if (direction =='right') {
newpos = parseInt(currentpos) + 300;
$('.slider').stop(true, true).animate({"margin-left": newpos}, 1000, "easeOutQuart");
}
但这有效
if (direction =='left' && !$('.slider').is(':animated')) {
newpos = parseInt(currentpos) - 300;
$('.slider').stop(true, true).animate({"margin-left": newpos}, 1000, "easeOutQuart");
}
else if (direction =='right' && !$('.slider').is(':animated')) {
newpos = parseInt(currentpos) + 300;
$('.slider').stop(true, true).animate({"margin-left": newpos}, 1000, "easeOutQuart");
}
问题是如果没有条件中的is(':animated')
,我怎么能这样做呢? stop()
在这种情况下应该完成工作吗?
答案 0 :(得分:0)
if (direction =='left') {
newpos = parseInt(currentpos) - 300;
}
else if (direction =='right') {
newpos = parseInt(currentpos) + 300;
}
$('.slider').animate({"margin-left": newpos}, 1000, "easeOutQuart");