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);”.
Leave A Comment