国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

js實現簡單的無縫輪播效果

瀏覽:107日期:2024-04-21 16:38:57

本文實例為大家分享了js實現簡單無縫輪播效果的具體代碼,供大家參考,具體內容如下

*{ margin: 0; padding: 0;}#box{ width: 500px; height: 200px; padding: 5px; margin: 50px auto; border: 1px solid #999999;}.inner{ width: 500px; height: 200px; overflow: hidden; position: relative;}ul,ol{ list-style: none; position: absolute;}ul{ width: 3000px; height: 200px;}li{ float: left;}ol{ right: 20px; bottom: 20px;}ol>li{ width: 25px; height: 25px; line-height: 25px; text-align: center; background-color: #fff; border-radius: 50%; margin-right: 10px; cursor: pointer;}ol>li.current{ background-color: orange; color: white;}.control{ display: none;}.control>span{ position: absolute; top: 50%; margin-top: -20px; display: inline-block; width: 25px; height: 40px; line-height: 40px; background-color: rgba(0,0,0,0.3); color: white; font-size: 20px; cursor: pointer; text-align: center;}.right{ right: 0;}

<div id='box'> <div class='inner'> <ul> <li><img src='http://www.cgvv.com.cn/bcjs/image/1.jpg' alt=''></li> <li><img src='http://www.cgvv.com.cn/bcjs/image/2.jpg' alt=''></li> <li><img src='http://www.cgvv.com.cn/bcjs/image/3.jpg' alt=''></li> <li><img src='http://www.cgvv.com.cn/bcjs/image/4.jpg' alt=''></li> <li><img src='http://www.cgvv.com.cn/bcjs/image/5.jpg' alt=''></li> </ul> <ol> <li class='current'>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ol> <div class='control'> <span class='left'><</span> <span class='right'>></span> </div> </div></div>

var box=document.getElementById('box');var ul=box.getElementsByTagName('ul')[0];var ol=box.getElementsByTagName('ol')[0];var olLiArr=ol.children;var control=box.getElementsByClassName('control')[0];ul.appendChild(ul.children[0].cloneNode(true));var index=0;var circleIndex=0;var timer=setInterval(autoPlay,2000);//鼠標移入移出box.onmouseover=function () { clearInterval(timer); control.style.display='block';};box.onmouseout=function () { timer=setInterval(autoPlay,2000); control.style.display='none';};//小圓點for (var i=0;i<olLiArr.length;i++) { olLiArr[i].index=i; olLiArr[i].onclick=function () { if(index===5){ ul.style.left=0; index=0; } for (var i=0;i<olLiArr.length;i++){ olLiArr[i].removeAttribute('class'); } this.setAttribute('class','current'); animate_constSpeed_x(ul,-this.index*500); index=this.index; circleIndex=this.index; }}//左右點擊control.children[1].onclick=function () { autoPlay();};control.children[0].onclick=function () { index--; if (index<0){ ul.style.left=-2500+'px'; index=4; } animate_constSpeed_x(ul,-index*500); circleIndex--; if (circleIndex<0){ circleIndex=4; } for (var i=0;i<olLiArr.length;i++) { olLiArr[i].removeAttribute('class'); } olLiArr[circleIndex].setAttribute('class','current');};

//自動輪播封裝function autoPlay() { index++; if (index>5){ ul.style.left=0; index=1; } animate_constSpeed_x(ul,-index*500); circleIndex++; if (circleIndex>4){ circleIndex=0; } for (var i=0;i<olLiArr.length;i++) { olLiArr[i].removeAttribute('class'); } olLiArr[circleIndex].setAttribute('class','current');}//勻速封裝function animate_constSpeed_x(ele,endX) { clearInterval(ele.timer); var step=(endX-ele.offsetLeft)>0?10:-10; ele.timer=setInterval(function () { ele.style.left=ele.offsetLeft+step+'px'; console.log(1); if(Math.abs(endX-ele.offsetLeft)<=Math.abs(step)){ clearInterval(ele.timer); ele.style.left=endX+'px'; } },10)}

js實現簡單的無縫輪播效果

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 日本国产最新一区二区三区 | 美女18网站 | 国产精品欧美亚洲 | 中文字幕一区二区小泽玛利亚 | 亚洲 欧美 成人日韩 | 在线亚洲成人 | 香蕉久久国产 | 久热色| 国产精品三级国语在线看 | 美日韩一区二区三区 | 最新在线步兵区 | 精品特级一级毛片免费观看 | 亚洲精品高清视频 | 欧美综合一区二区三区 | 中文一区在线 | 国产精品久久久久久影院 | 视频二区精品中文字幕 | 最新国产午夜精品视频不卡 | 成人黄激情免费视频 | 日韩在线一区二区三区免费视频 | 欧美日比视频 | 国产久草在线 | 91精品国产福利尤物免费 | 韩国福利一区 | 亚洲小视频 | 欧美13一14sexvideo欧 | 精品欧美亚洲韩国日本久久 | 亚洲综合国产精品 | 在线亚州 | 先锋影音xfyy5566男人资源 | 欧美日韩亚洲综合在线一区二区 | 在线 | 一区二区三区 | 国产精品久久久久久久免费 | 欧美在线亚洲国产免m观看 欧美在线一级精品 | 91理论片| 日韩三级在线观看视频 | 亚洲韩国日本欧美一区二区三区 | 精品国产一区二区三区不卡 | 一级特级毛片免费 | 欧美一级欧美三级在线观看 | 免费刺激视频 |