それぞれに多くのアニメーションが含まれる通常の ( ajax 以外の) 関数に問題があります。現在、私は単純に機能間を持っていますが、ブラウザやコンピューターが同じではないため、これは完璧ではありません。setTimeout
追加の注意: どちらも衝突する個別のアニメーション/その他を持っています。
別のコールバック関数に単純に入れることはできません
// multiple dom animations / etc
FunctionOne();
// What I -was- doing to wait till running the next function filled
// with animations, etc
setTimeout(function () {
FunctionTwo(); // other dom animations (some triggering on previous ones)
}, 1000);
とにかくjs/jQueryにあるものはありますか:
// Pseudo-code
-do FunctionOne()
-when finished :: run -> FunctionTwo()
$.when()
&については知って$.done()
いますが、それらはAJAX用です...
- 私の更新されたソリューション
jQuery には、現在行われているアニメーションの配列を保持する $.timers という変数 (何らかの理由で jQuery ドキュメントのどこにもリストされていません) があります。
function animationsTest (callback) {
// Test if ANY/ALL page animations are currently active
var testAnimationInterval = setInterval(function () {
if (! $.timers.length) { // any page animations finished
clearInterval(testAnimationInterval);
callback();
}
}, 25);
};
基本的な使い方:
// run some function with animations etc
functionWithAnimations();
animationsTest(function () { // <-- this will run once all the above animations are finished
// your callback (things to do after all animations are done)
runNextAnimations();
});