テスト Web ページの小さなスライドショーを作成しようとしています。なぜこのコードが機能しないのか、私は混乱しています (私は JavaScript の経験があまりなく、主に Java を扱っています。Javascript はかなりイライラするものです)。また、実行を開始し、数秒後に 3 番目の画像に切り替わり、停止して二度と切り替わらないことを追加したいと思います。
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);