JQuery: What is the difference between stop (true) and clearQueue ()

What is the difference between using a parameter stop()with a parameter clearQueueset to true and just using clearqueue(), and if there is no difference, why both?

+5
source share
2 answers

From api, docs .stop()is for animation only, however it .clearqueue()will remove any function attached to the standard jquery queue.

From docs :

.clearQueue() , , . ,.clearQueue() fx, . , .stop(true). , .stop() ,.clearQueue() , jQuery .queue().

+7

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');

Watch the demo.

+1
source

All Articles