jQuery > Effects methods

.delay() - Delay execution of method in jQuery

How to delay the execution of a subsequent method in jQuery?


To delay the execution of the subsequent method, delay() method can be used. It accepts number of milliseconds as parameter.

<input type="button" id="btnDelay" value="Click and Delay Animation" /></p>

<div id="divDelay" style="height: 50px; width: 50px; background: green; 
left: 0px; display: none; position: absolute;"> </div>

<script> $("#btnDelay").click(function () { $("#divDelay").slideDown().delay(500).fadeOut(); });
</script>

In the above code snippet, on click of “btnDelay”, “divDelay” element is shown with sliding effect (.slideDown()) and then it will wait for 500 milliseconds and then .fadeOut effect will start that will hide the element.

 Views: 4326 | Post Order: 102



Write for us






Hosting Recommendations