📜  引导程序每秒更改图像 - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:58.238000             🧑  作者: Mango

代码示例1
var counter = 1; //instantiate a counter
var maxImage = 5; //the total number of images that are available
setInterval(function() {
    document.querySelector('header').style.backgroundImage = "url('images/" + (counter + 1) + ".jpg')";
    if (counter + 1 == maxImage) {
        counter = 0; //reset to start
    } else {
        ++counter; //iterate to next image
    }
}, 10000);