JS圖片自動輪換效果實現

來源:互聯網
上載者:User

今天不在狀態,五一快到了,俺就特想玩了。好了,天色已晚,閑話不多說,看下用javaScript 實現的圖片自動輪換效果,先看圖片


下面是具體的代碼,還是比較簡單的。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>越獄的囚徒</title><style type="text/css">.content{border:3px solid red;padding:3px;width:500px;height:245px;position:relative;}.content img{border:0;}.content div{position:absolute;z-index:1000;border:2px solid green;padding:3px 5px;background:#ccc;}.content .cur{background:red;color:white;}//當前顯示的圖片的小方塊,紅色背景白色字型</style><script type="text/javascript">var arr=['images/1.jpg','images/2.jpg','images/3.jpg','images/4.gif','images/5.jpg'];var i=0;var ob,obk;function lunhuan(){if(i>4){//數字大於4就從0開始i=0;}ob=document.getElementById("image1");ob.src=arr[i];//所有div-0到div-4,背景顏色置灰for(var j=0;j<=4;j++){document.getElementById("div-"+j).style.backgroundColor='#ccc';document.getElementById("div-"+j).style.color='black';}obk=document.getElementById("div-"+i);obk.style.backgroundColor='red';obk.style.color='white';i++;}</script></head><body onload="window.setInterval(lunhuan,1000);"><div class="content"><img id="image1" src="images/1.jpg"/><div class="cur" id="div-0" style="top:215px;right:128px;">1</div><div id="div-1" style="top:215px;right:98px;">2</div><div id="div-2" style="top:215px;right:68px;">3</div><div id="div-3" style="top:215px;right:38px;">4</div><div id="div-4" style="top:215px;right:8px;">5</div></div><input type="button" value="test" onclick="lunhuan();"/></body></html>
簡單的說下流程:

1.先定義最外層的DIV

2.再定義緊挨著的圖片DIV

3.圖片右下角的小方塊DIV

用計時器函數,實現圖片輪換,並讓小方塊也產生對於的變化。

OK,睡覺。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.