2011-03-29 99 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

相关问题