《javaScript100例|04》自动播放——Js幻灯片缓冲效果
生活随笔
收集整理的這篇文章主要介紹了
《javaScript100例|04》自动播放——Js幻灯片缓冲效果
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
目錄
效果圖
示例
源碼地址:
效果圖
?
示例
<html> <head> <title>自動(dòng)播放——幻燈片緩沖效果</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:492px;height:172px;background:#fff;border-radius:5px;border:8px solid #fff;margin:10px auto;cursor:pointer;} #box .list{position:relative;width:490px;height:170px;overflow:hidden;} #box .list ul{position:absolute;top:0;left:0;} #box .list li{width:490px;height:170px;overflow:hidden;} #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 oList = oBox.getElementsByTagName("ul")[0];var aImg = oBox.getElementsByTagName("img");var timer = playTimer = null;var index = i = 0;var bOrder = true;var aTmp = [];//生成數(shù)字按鈕for (i = 0; i < aImg.length; i++){aTmp.push("<li>" + (i + 1) + "</li>")}//插入元素var oCount = document.createElement("ul");oCount.className = "count"oCount.innerHTML = aTmp.join("");oBox.appendChild(oCount);//初始化狀態(tài)var aBtn = oBox.getElementsByTagName("ul")[1].getElementsByTagName("li");aBtn[index].className = "current";//按鈕點(diǎn)擊切換for (i = 0; i < aBtn.length; i++){aBtn[i].index = i;aBtn[i].onclick = function (){index = this.index;for (i = 0; i < aBtn.length; i++) aBtn[i].className = "";this.className = "current"; startMove(-(this.index * aImg[0].offsetHeight)) }}//鼠標(biāo)移入展示區(qū)停止自動(dòng)播放oBox.onmouseover = function (){clearInterval(playTimer)};//鼠標(biāo)離開(kāi)展示區(qū)開(kāi)始自動(dòng)播放oBox.onmouseout = function (){autoPlay()};//頁(yè)面加載即調(diào)用自動(dòng)播放oBox.onmouseout();//自動(dòng)播放函數(shù)function autoPlay(){playTimer = setInterval(function (){bOrder ? index++ : index--; index == aBtn.length - 1 && (bOrder = false);index == 0 && (bOrder = true);aBtn[index].onclick();startMove(-(index * aImg[0].offsetHeight))}, 3000)}function startMove(iTarget){clearInterval(timer);timer = setInterval(function (){doMove(iTarget)}, 30) }function doMove (iTarget){var iSpeed = (iTarget - oList.offsetTop) / 10;iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed); oList.offsetTop == iTarget ? clearInterval(timer) : oList.style.top = oList.offsetTop + iSpeed + "px"} }; </script> </head> <body> <div id="box"><div class="list"><ul><li><img src="wall5.jpg" width="490" height="170" /></li><li><img src="wall6.jpg" width="490" height="170" /></li><li><img src="wall7.jpg" width="490" height="170" /></li></ul></div> </div> </body> </html>?
源碼地址:
自動(dòng)播放——Js幻燈片緩沖效果.rar-互聯(lián)網(wǎng)文檔類資源-CSDN下載https://download.csdn.net/download/weixin_41937552/37380676
總結(jié)
以上是生活随笔為你收集整理的《javaScript100例|04》自动播放——Js幻灯片缓冲效果的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 《javaScript100例|03》自
- 下一篇: vue安装教程及简介