js實現簡單的圖片輪播

來源:互聯網
上載者:User

標籤:

js代碼如下

 1 <script type="text/javascript"> 2 var n=1; 3 var map=new Array(); 4 map[0]=new Image(); 5 map[1]=new Image(); 6 map[2]=new Image(); 7 map[3]=new Image(); 8 map[4]=new Image(); 9 map[5]=new Image();10 map[0].src="images/0.jpg";11 map[1].src="images/1.jpg";12 map[2].src="images/2.jpg";13 map[3].src="images/3.jpg";14 map[4].src="images/4.jpg";15 map[5].src="images/5.jpg";16 function disp()17 {18 document.getElementById("img1").src=map[n].src;19 n=n+1;20 if (n>5)21 n=0;22 window.setTimeout("disp();",2000);23 }24 window.setTimeout("disp();",2000);25 </script>

自己替換掉圖片地址和名稱,以及切換時間。2000表示2秒 。

 

然後在<body>和</body>中間加上下面一段代碼。

1 <div id="content1">2 <img id="img1" src="images/0.jpg" width="100%" height="300px">3 </div>

 

js實現簡單的圖片輪播

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.