0

所以这段代码没有做我期望它做的事情,停止什么都不做,它一直在动画给出奇怪的结果,(因为 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()做这项工作吗?

4

1 回答 1

0
if (direction =='left') {
    newpos = parseInt(currentpos) - 300;
}
else if (direction =='right') {
    newpos = parseInt(currentpos) + 300;
}
$('.slider').animate({"margin-left": newpos}, 1000, "easeOutQuart");
于 2012-05-17T10:09:46.723 回答