Jquery delay () introduction and instructions
- 2020-03-30 03:50:36
- OfStack
Delay (duration, queueName)
Set a delay to delay the execution of later items in the queue.
New to jQuery 1.4. Used to delay the execution of functions in a queue. It can either delay the execution of an animated queue, or it can be used for a custom queue.
-sheldon: the duration of the event is milliseconds
QueueName: queue noun, default Fx, animated queue.
parameter | describe |
---|---|
speed | Optional. Set the speed of the delay.
Possible values:
|
queueName | Optional. Specify the name of the queue. The default is "fx" , the standard effect queue. |
$("button").click(function(){
$("#div1").delay("slow").fadeIn();
$("#div2").delay("fast").fadeIn();
});
Complete test code:
<!DOCTYPE html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").delay("slow").fadeIn();
$("#div2").delay("fast").fadeIn();
$("#div3").delay(800).fadeIn();
$("#div4").delay(2000).fadeIn();
$("#div5").delay(4000).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:red;"></div><br>
<div id="div5" style="width:90px;height:90px;display:none;background-color:purple;"></div><br>
</body>
</html>
Ex. :
Head and bottom lazy loading animation
$(document).ready(function() {
$('#header')
.css({ 'top':-50 })
.delay(1000)
.animate({'top': 0}, 800);
$('#footer')
.css({ 'bottom':-15 })
.delay(1000)
.animate({'bottom': 0}, 800);
});