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 onl oad = "run();">
        
        <img id="banner" alt="banner" src="001.jpg">
        
    </body>
</html>

 

上一篇:44.Linked List Cycle II(环的入口节点)


下一篇:LeetCode 141 Linked List Cycle 142 Linked List Cycle II