2016-03-30 61 views
1

整個問題是,我有一個頭是固定的,並有一個div下,我需要相應地移動。雖然如果我點擊的速度真的很快,例如3到4倍的動畫混亂,我最終會在內容中包含「下」div。我在動畫和滑動之前使用停止。我嘗試使用隊列等無效。與動畫jQuery重疊問題

$(".header").click(function() { 

    $header = $(this); 
    $content = $header.next(); 
    $content.stop().slideToggle(500, function() { 
    if(($('.lol').css('margin-top')) == '47px') 
{ 
$(".under").stop().animate({'margin-top': "100px"}, 500) 
} 
else 
{ 
$(".under").stop().animate({'margin-top': "47px"}, 500) 
} 
    }); 
}); 

https://jsfiddle.net/zddzvxLy/8/

這裏的jsfiddle顯示的問題。試着點擊表頭幾次實在是快,「這必須是「會出現內部CONTENT下

回答

1

首先,你有沒有與類.lol項目 - 更改到.under

其次,改變你的stop()調用stop(true, true)

第三,我想德e您的動畫調用.under中的completed函數,並將其與第一個動畫並行調用。

https://jsfiddle.net/zddzvxLy/10/

+0

對不起,我想一切從笑改爲下這樣的代碼會更容易理解和錯過了一個。無論如何,停止(真實,真實)並不能解決問題。 – Argus

+0

在我的示例中(小提琴的修訂版本10),問題不再存在。 – Dutchie432

+0

看起來問題已解決。謝謝。只要它允許我接受這個答案。 我檢查了停止的文件,現在變得清楚了。 .stop([clearQueue] [,jumpToEnd]) 謝謝! – Argus

0

避免調用animate()當元素已經被動畫:

if ($('.content').is(':animated') === false) 
{ 
    // animate 
} 
else 
{ 
    return false; 
}