2011-03-29 35 views

回答

7

從api文檔中,.stop()僅用於動畫,但.clearqueue()將刪除任何附加到標準jQuery隊列的函數。

docs

當.clearQueue()方法是 叫,但沒有執行在隊列 所有功能都 從隊列中刪除。當使用 而沒有參數時,.clearQueue() 將從 fx(標準特技隊列)中刪除剩餘的功能。在 這種方式它類似於.stop(true)。 然而,雖然.stop()方法是 意味着僅與動畫一起使用, .clearQueue()也可以被用來 刪除已經 加入到一個通用的jQuery隊列 的.queue任何功能( ) 方法。

1

jQuery支持多個隊列,其中最常見的是fx動畫隊列。 .stop()僅適用於fx隊列,而clearQueue可讓您指定其他(自定義)隊列。


這裏是與自定義隊列的示例:

// First function to queue 
function a1(next) { 
    setTimeout(function() { 
     alert("one"); 
     next(); 
    }, 1000); 
} 

// Second function to queue 
function a2(next) { 
    setTimeout(function() { 
     alert("two"); 
     next(); 
    }, 1000); 
} 

// Queue both functions and start it off 
$('body').queue('alerts', a1).queue('alerts', a2).dequeue('alerts'); 

// Clear the queue to prevent the second alert from showing 
$('body').clearQueue('alerts'); 

demo

相關問題