js 图片轮播简单版

<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script>
            window.onload=function(){
                setInterval("rollImg()",2000);
            }
            var imgarr=["https://www.w3school.com.cn/i/eg_tulip.jpg",
			"https://www.w3school.com.cn/i/eg_chinarose.jpg",
		        "https://www.runoob.com/images/pulpit.jpg"]
            var i = 1;
            function rollImg(){
                i++;
                if(i == 4){
                    i = 1;
                }
                var img_id = document.getElementById("img_id");
                img_id.src= imgarr[i-1];
            }
        </script>
    </head>
    <body>
        <center>
            <div style="width: 1200px; height: 800px; border: 5px solid purple; overflow: hidden;">
                <img src="https://www.w3school.com.cn/i/eg_tulip.jpg" id="img_id"/>
            </div>
        </center>
    </body>
</html>

 这是简单的原生js图片轮播,复制代码保存为网页即可看到效果。如有错误和不足之处,欢迎指正 

posted @ 2020-04-07 20:14  就看你一眼  阅读(396)  评论(0编辑  收藏  举报