我想在加载后的前 5 秒内显示,每 1 秒或更短时间显示不同的背景。在这 5 秒之后,我想设置一个明确的背景。
我已经设置了我的 div 类:
<div id="plateau" class="step01">
<div id="plateau-fond">
然后我在我的 CSS 中设置了背景:
#plateau.step-01 #plateau-fond
{
background-image:url('../img/plateau-03-step-01.png');
}
我想使用 javascript 或 jQuery 来执行上面提到的。
最佳答案
在我的脑海中,我建议如下:
$(function() {
var step = 1;
var interval = window.setInterval(function() {
var $plateau = $("#plateau");
$plateau.removeClass("step0" + step);
step++;
$plateau.addClass("step0" + step);
if(step == 5) {
window.clearInterval(interval);
}
}, 1000);
});
稍后将在 jsfiddle 中验证这一点。
关于javascript - 在 5 秒内加载后显示不同的背景,然后最终更改它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12833234/