EXAMPLE
HTML
<div id="myBackground"></div>
CSS
#myBackground {
bottom: 0;
left: 0;
position: fixed;
right: 0;
top: 0;
background: url(http://jsfiddle.net/img/initializing.png) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
JavaScript
var imgUrl = "url(http://cdn.css-tricks.com/wp-content/themes/CSS-Tricks-10/images/bg.png)";
$(function() { // starts when page is loaded and ready
setTimeout(function() {
$("#myBackground").css("background-image", imgUrl);
}, 2000); // 2 second timer
})
Alternate Style (with FadeIn/Out effect)
HTML
<div id="myBackground">
<img src="http://jsfiddle.net/img/initializing.png" />
<img src="http://cdn.css-tricks.com/wp-content/themes/CSS-Tricks-10/images/bg.png" />
</div>
CSS
#myBackground {
bottom: 0;
left: 0;
position: fixed;
right: 0;
top: 0;
}
#myBackground img {
height: 100%;
width: 100%;
}
#myBackground img:nth-child(2) {
display: none;
}
JavaScript
$(function() { // starts when page is loaded and ready
setTimeout(function() {
$("#myBackground img:nth-child(1)").fadeOut("slow");
$("#myBackground img:nth-child(2)").fadeIn(1500);
}, 2000); // 2 second timer
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…