How to change image-background after sometime?

前端 未结 5 403
别跟我提以往
别跟我提以往 2021-01-15 15:40

HI everybody

i need to know if there are a way to change the background image after a specific time like 10 sec or 30 sec...etc. you know like yahoo Login mail \"it\

5条回答
  •  爱一瞬间的悲伤
    2021-01-15 16:42

    You could do it with a function and setTimeout:

    function changeBG()
    {
        var body = document.getElementsByTagName("body")[0];
        body.style.backgroundImage = "url(myimage.gif)";
        setTimeout("changeBG",30000); // Change every 30 seconds
    }
    
    window.onload = changeBG;
    

    (untested so it might need a tweak or 2)

提交回复
热议问题