问题
I have a div that I would like to delay onLoad for a set period of time using jQuery. Here is the code I have that isn't working:
$('#PriceBox').delay(8000).fadeIn(400);
回答1:
CSS:
/** make sure the element is initially hidden */
#PriceBox {
display: none;
}
jQuery:
$(document).ready(function() {
$('#PriceBox').delay(8000).fadeIn(400);
});
- DEMO
回答2:
In order to do this you need to start off your div
as display: none
and then put the display code in a $(document).ready(..)
<div id="PriceBox" style="display: none">Delay load me</div>
Javascript
$(document).ready(function() {
$('#PriceBox').delay(1000).fadeIn(1000);
});
Fiddle: http://jsfiddle.net/6B6he/
来源:https://stackoverflow.com/questions/9672580/delay-div-onload