尝试为测试网页制作一个小幻灯片。我对为什么这段代码不起作用感到困惑(我对 javascript 不是很有经验,我主要处理 Java,Javascript 相当令人沮丧)。另外我想添加它确实开始运行它会在几秒钟后切换到第三张图片然后它停止不再切换。
var backgroundElement = document.getElementById("innerContent");
var minibarImage1 = document.getElementById("pic1");
var minibarImage2 = document.getElementById("pic2");
var minibarImage3 = document.getElementById("pic3");
minibarImage1.onmouseover = function(){
backgroundElement.style.backgroundImage="url('images/frontpage/maintenance_01.jpg')";
};
minibarImage2.onmouseover = function() {
backgroundElement.style.backgroundImage ="url('images/frontpage/natural_steps_01.jpg')";
};
minibarImage3.onmouseover = function() {
backgroundElement.style.backgroundImage = "url('images/frontpage/twnshp_bdg_01b.jpg')";
};
function slideshow() {
setTimeout(function(){backgroundElement.style.backgroundImage= "url('images/frontpage/maintenance_01.jpg')";}, 2000);
setTimeout(function(){backgroundElement.style.backgroundImage = "url('images/frontpage/natural_steps_01.jpg')";}, 2000);
setTimeout(function(){backgroundElement.style.backgroundImage = "url('images/frontpage/twnshp_bdg_01b.jpg')";}, 2000);
}
window.onload = setInterval(function(){slideshow();}, 8000);