新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
原生js如何實現(xiàn)輪播特效
這篇文章主要為大家展示了“原生js如何實現(xiàn)輪播特效”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“原生js如何實現(xiàn)輪播特效”這篇文章吧。
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:域名與空間、網(wǎng)絡(luò)空間、營銷軟件、網(wǎng)站建設(shè)、下花園網(wǎng)站維護、網(wǎng)站推廣。
首先css代碼
a{text-decoration:none;color:#3DBBF5;} *{ margin: 0; padding: 0; } .wrapper{ width: 400px; height: 300px; margin: 100px auto; } #lunbo{ position: relative; overflow: hidden; } #list{ position: relative; white-space: nowrap; // 這塊用行元素模擬,所以才用該屬性,塊元素可修改這塊 } #list span{ display: inline-block; width: 400px; height: 300px; text-align: center; line-height: 300px; font-weight: bold; font-size: 100px; color: #fff; } #buttons{ position: absolute; bottom: 0; text-align: center; width: 100%; height: 40px; line-height: 40px; } #buttons span{ display: inline-block; width: 15px; height: 5px; background: #fff; margin: 0 10px; cursor: pointer; transition: all .5s; } #buttons span.on{ height: 20px; } .arrow{ position: absolute; top: 50%; transform: translateY(-50%); font-size: 80px; font-weight: bold; color: #fff; opacity: .3; transition: all .5s; } .wrapper:hover .arrow{ opacity: 1; } #prev{ left: 10px; } #next{ right: 10px; }
然后HTML代碼
最后js代碼
window.onload=function () { var lunBo = document.getElementById("lunbo"); var list = document.getElementById("list"); var btn = document.getElementById("buttons").getElementsByTagName('span'); var prev = document.getElementById("prev"); var next = document.getElementById('next'); var interval = 3000; var timer; var index = 1; var animated = false; for (var i=0;i0 && parseInt(list.style.left) newLeft)) { //通過條件判斷到它是否還要繼續(xù)進行動畫 list.style.left = parseInt(list.style.left) + speed +'px'; setTimeout(go,interval) } else{ animated = false; //動畫狀態(tài)結(jié)束 list.style.left = newLeft + 'px'; //現(xiàn)在的位移 if (parseInt(list.style.left)<-2000) { // 輔助假圖 list.style.left = -400 + 'px'; } else if( parseInt(list.style.left)>-400){ list.style.left = -2000 + 'px'; } } } go(); } function play () { timer = setTimeout(function () { next.onclick(); play(); },interval) } play(); function stop () { clearTimeout(timer); } lunBo.onmouseover=stop; lunBo.onmouseout=play; }
以上是“原生js如何實現(xiàn)輪播特效”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
分享名稱:原生js如何實現(xiàn)輪播特效
分享網(wǎng)址:http://www.dlmjj.cn/article/ipdehd.html