Description:
The Jquery clearQueue() method removes all queued items from the queue that have not yet been executed. When the .clearQueue() method is executed then all functions on the queue that have not been executed are removed from the queue. If there is no argument then the clearQueue() will remove all the remaining functions.
Syntax
$(selector).clearQueue( queueName)
queueName | It contain the name of the queue. Defaults it will be fx . |
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> </script> <script type="text/javascript"> $(document).ready(function () { var divBox = $("#divBox"); $("#divStart").click(function () { divBox.animate({ height: 200 }, 2000); divBox.slideUp(2000); divBox.slideDown(2000); divBox.animate({ width: 300 }, 1500); divBox.animate({ height: 100 }, 1500); divBox.animate({ width: 100 }, 1500); }); $("#divStop").click(function () { divBox.clearQueue(); }); }); </script> </head> <body> <button id="divStart">Start Animation</button> <button id="divStop">Stop Animation</button> <br><br> <div id="divBox" style="background: #00ff21; height: 100px; width: 100px;"></div> </body> </html> |
Output:
Clicking on “Start Animation”” button, the “divBox” start with animations and stop the execution after calling the clearqueue() function. From the below output, ” divBox.animate({ width: 300 }, 1500);divBox.animate({ height: 100 }, 1500);divBox.animate({ width: 100 }, 1500);” animation steps has cleared from the queue after clicking the “stop animation” button while executing “divBox.slideDown(2000);”.