本文實(shí)例講述了JS實(shí)現(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" class="act"> <img src="img/2.jpg" > <img src="img/3.jpg" > <img src="img/4.jpg" > <img src="img/5.jpg" > <img src="img/6.jpg" > <img src="img/7.jpg" > <img src="img/8.jpg" > <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>
當(dāng)前標(biāo)題:JS實(shí)現(xiàn)頭條新聞的經(jīng)典輪播圖效果示例-創(chuàng)新互聯(lián)
瀏覽地址:http://aaarwkj.com/article20/cojpjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、響應(yīng)式網(wǎng)站、Google、搜索引擎優(yōu)化、靜態(tài)網(wǎng)站、全網(wǎng)營銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容