1. 程式人生 > >圖片自動播放

圖片自動播放

<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script>
        function rollback(){
            setInterval("rollImg()",2000);
        }

        var i = 1;
        function rollImg(){
            i++;
            if(i === 6){
                i = 1;
            }
            var img_id = document.getElementById("img_id");
            img_id.src = "img/"+i+".jpg"
        }
    </script>
</head>
<body onload="rollback()">

    <div style="width: 1200px; height: 800px; border: 5px solid purple; overflow: hidden;">
        <img src="img/1.jpg" id="img_id"/>
    </div>

</body>
</html>