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 に答える