本文實(shí)例講述了JS實(shí)現(xiàn)可切換圖片的幻燈切換效果。分享給大家供大家參考,具體如下:
<!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>JS切換圖片幻燈切換效果</title> <style> body, div, ul, li { margin: 0; padding: 0; } ul { list-style-type: none; } body { background: #000; text-align: center; font: 12px/20px Arial; } #box { position: relative; width: 322px; height: 172px; background: #fff; border-radius: 5px; border: 8px solid #fff; margin: 10px auto; } #box .list { position: relative; width: 320px; height: 240px; overflow: hidden; border: 1px solid #ccc; } #box .list li { position: absolute; top: 0; left: 0; width: 320px; height: 240px; opacity: 0; filter: alpha(opacity=0); } #box .list li.current { opacity: 1; filter: alpha(opacity=100); } #box .count { position: absolute; right: 0; bottom: 5px; } #box .count li { color: #fff; float: left; width: 20px; height: 20px; cursor: pointer; margin-right: 5px; overflow: hidden; background: #F90; opacity: 0.7; filter: alpha(opacity=70); border-radius: 20px; } #box .count li.current { color: #fff; opacity: 1; filter: alpha(opacity=100); font-weight: 700; background: #f60; } #tmp { width: 100px; height: 100px; background: red; position: absolute; } </style> <script type="text/javascript"> window.onload = function() { var oBox = document.getElementById("box"); var aUl = document.getElementsByTagName("ul"); var aImg = aUl[0].getElementsByTagName("li"); var aNum = aUl[1].getElementsByTagName("li"); var timer = play = null; var i = index = 0; var bOrder = true; //切換按鈕 for(i = 0; i < aNum.length; i++) { aNum[i].index = i; aNum[i].onmouseover = function() { show(this.index) } } //鼠標(biāo)劃過關(guān)閉定時(shí)器 oBox.onmouseover = function() { clearInterval(play) }; //鼠標(biāo)離開啟動自動播放 oBox.onmouseout = function() { autoPlay() }; //自動播放函數(shù) function autoPlay() { play = setInterval(function() { //判斷播放順序 bOrder ? index++ : index--; //正序 index >= aImg.length && (index = aImg.length - 2, bOrder = false); //倒序 index <= 0 && (index = 0, bOrder = true); //調(diào)用函數(shù) show(index) }, 2000); } autoPlay();//應(yīng)用 function show(a) { index = a; var alpha = 0; for(i = 0; i < aNum.length; i++)aNum[i].className = ""; aNum[index].className = "current"; clearInterval(timer); for(i = 0; i < aImg.length; i++) { aImg[i].style.opacity = 0; aImg[i].style.filter = "alpha(opacity=0)"; } timer = setInterval(function() { alpha += 2; alpha > 100 && (alpha = 100); aImg[index].style.opacity = alpha / 100; aImg[index].style.filter = "alpha(opacity = " + alpha + ")"; alpha == 100 && clearInterval(timer) }, 20); } }; </script> </head> <body> <div id="box"> <ul class="list"> <li class="current"><img src="img/3.jpg" width="320" height="240"/></li> <li><img src="img/1.jpg" width="320" height="240"/></li> <li><img src="img/2.jpg" width="320" height="240"/></li> <li><img src="img/3.jpg" width="320" height="240"/></li> <li><img src="img/4.jpg" width="320" height="240"/></li> </ul> <ul class="count"> <li class="current">1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> </div> </body> </html>
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)站標(biāo)題:JS實(shí)現(xiàn)可切換圖片的幻燈切換效果示例-創(chuàng)新互聯(lián)
網(wǎng)頁地址:http://aaarwkj.com/article26/cdhdjg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、域名注冊、虛擬主機(jī)、網(wǎng)站改版、企業(yè)建站、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容