jQuery delay()

Introduction

Delay different <div> elements:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/* w ww .j  av a2s.  c  o m*/
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#div1").delay("slow").fadeIn();
    $("#div2").delay("fast").fadeIn();
    $("#div3").delay(800).fadeIn();
    $("#div4").delay(4000).fadeIn();
    $("#div5").delay(2000).fadeIn();
  });
});
</script>
</head>
<body>

<p>This example sets different speed values for the delay() method.</p>
<button>Click to fade in boxes with a delay</button>
<br><br>

<div id="div1" style="width:90px;height:90px;display:none;background-color:black;"></div><br>
<div id="div2" style="width:90px;height:90px;display:none;background-color:green;"></div><br>
<div id="div3" style="width:90px;height:90px;display:none;background-color:blue;"></div><br>
<div id="div4" style="width:90px;height:90px;display:none;background-color:yellow;"></div><br>
<div id="div5" style="width:90px;height:90px;display:none;background-color:purple;"></div><br>

</body>
</html>

The delay() method sets a timer to delay the execution of the next item in the queue.

Syntax

$(selector).delay(speed,queueName)
Parameter
Optional
Description
speed




Optional.




speed of the delay
Possible values:
milliseconds
"slow"
"fast"
queueName

Optional.

name of the queue
Default is "fx", the standard effects queue



PreviousNext

Related