JS實現(xiàn)頭條新聞的經(jīng)典輪播圖效果示例
本文實例講述了JS實現(xiàn)頭條新聞的經(jīng)典輪播圖效果。分享給大家供大家參考,具體如下:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> *{ margin:0; padding:0; list-style: none; } .box{ width: 665px; height: 362px; border: solid; margin: 100px auto; position:relative ; } .left{ width: 50px; height: 50px; border: solid white; border-radius: 50%; position: absolute; line-height: 50px; text-align: center; font-size: 50px; left:0px; top:180px; cursor: pointer; color: white; } .right { width: 50px; height: 50px; border: solid white; border-radius: 50%; position: absolute; line-height: 50px; text-align: center; font-size: 50px; right: 0px; top: 180px; cursor: pointer; color: white; } ul{ width: 400px; height: 50px; margin:307px 188px; position: absolute; left:30px; top:24px; } li{ width: 30px; height: 30px; border: solid 1px white; border-radius: 50%; float: left; cursor: pointer; line-height: 30px; text-align: center; color: white; } img{ display: none; width: 665px; height: 362px; } .act{display: block; } .active{ background: black; } </style> </head> <body> <div class="box" id="box"> <img src="img/1.jpg" alt="" class="act"> <img src="img/2.jpg" alt=""> <img src="img/3.jpg" alt=""> <img src="img/4.jpg" alt=""> <img src="img/5.jpg" alt=""> <img src="img/6.jpg" alt=""> <img src="img/7.jpg" alt=""> <img src="img/8.jpg" alt=""> <div class="left" id="left"> < </div> <div class="right" id="right"> > </div> <ul> <li class="active">1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> <li>7</li> <li>8</li> </ul> </div> <script> window.onload=function () { var arrLi=document.getElementsByTagName("li"); var arrImg=document.getElementsByTagName("img"); var oLeft=document.getElementById("left"); var oRight=document.getElementById("right"); var oBox=document.getElementById("box"); var num=0; f=setInterval(abc,1000); oBox.onmouseover=function () { clearInterval(f) } oBox.onmouseout=function () { f=setInterval(abc,1000); } for(x=0;x<arrLi.length;x++) { arrLi[x].index=x; arrLi[x].onmouseover=function () { for(j=0;j<arrLi.length;j++){ arrLi[j].className=""; arrImg[j].className=""; } this.className="active"; arrImg[this.index].className="act"; } } oLeft.onclick=function () { num=num-1; if(num<0){ num=arrImg.length-1 } for(j=0;j<arrImg.length;j++){ arrImg[j].className=""; arrLi[j].className=""; }arrImg[num].className="act"; arrLi[num].className="active"; } oRight.onclick=abc function abc() { num=num+1; if(num>arrImg.length-1){ num=0 } for(j=0;j<arrImg.length;j++){ arrImg[j].className=""; arrLi[j].className=""; }arrImg[num].className="act"; arrLi[num].className="active"; } } </script> </body> </html>
本機測試運行效果如下:
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript圖片操作技巧大全》、《JavaScript切換特效與技巧總結(jié)》、《JavaScript運動效果與技巧匯總》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運算用法總結(jié)》
希望本文所述對大家JavaScript程序設(shè)計有所幫助。
相關(guān)文章
javascript實現(xiàn)簡單的鼠標(biāo)拖動效果實例
這篇文章主要介紹了javascript實現(xiàn)簡單的鼠標(biāo)拖動效果,實例分析了javascript鼠標(biāo)拖動效果的相關(guān)要點與實現(xiàn)技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04原生JS forEach()和map()遍歷的區(qū)別、兼容寫法及jQuery $.each、$.map遍歷操作
這篇文章主要介紹了原生JS forEach()和map()遍歷的區(qū)別、兼容寫法及jQuery $.each、$.map遍歷操作,結(jié)合實例形式分析了JS使用forEach()和map()以及jQuery使用$.each、$.map進行遍歷操作相關(guān)技巧與操作注意事項,需要的朋友可以參考下2019-02-02Electron autoUpdater實現(xiàn)Windows安裝包自動更新的方法
這篇文章主要介紹了Electron autoUpdater實現(xiàn)Windows安裝包自動更新的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-12-12150行代碼帶你實現(xiàn)微信小程序中的數(shù)據(jù)偵聽
在這篇文章中, 我將用150行代碼, 手把手帶你打造一個小程序也可以使用的偵聽器,感興趣的朋友跟隨小編一起看看吧2019-05-05