JavaScript实现的图片循环播放

直接上干货

<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>

 

posted @ 2019-06-14 14:35  代码沉思者  阅读(4209)  评论(0编辑  收藏  举报