JavaScript實現的圖片循環播放

直接上乾貨html

<html>
    <head>
        <title>Banner Cycler</title>
        <script>
            var banners = ["001.jpg","002.jpg","003.jpg"]; // 圖片地址
            var counter = 0;
            function run(){
                setInterval(cycle,1000);  //重複運行cycle函數,週期100ms
            }
            function cycle(){
                counter++;
                if(counter == banners.length)    
                    counter = 0;
                document.getElementById("banner").src = banners[counter];
            }
        </script>
    </head>
    <body onload = "run();">
        
        <img id="banner" alt="banner" src="001.jpg">
        
    </body>
</html>
相關文章
相關標籤/搜索