欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js實(shí)現(xiàn)簡(jiǎn)單的無縫輪播效果

 更新時(shí)間:2020年09月05日 15:23:35   作者:郝鑫蕓  
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)簡(jiǎn)單的無縫輪播效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js實(shí)現(xiàn)簡(jiǎn)單無縫輪播效果的具體代碼,供大家參考,具體內(nèi)容如下

*{
 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="image/1.jpg" alt=""></li>
  <li><img src="image/2.jpg" alt=""></li>
  <li><img src="image/3.jpg" alt=""></li>
  <li><img src="image/4.jpg" alt=""></li>
  <li><img src="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);
//鼠標(biāo)移入移出
box.onmouseover=function () {
 clearInterval(timer);
 control.style.display="block";
};
box.onmouseout=function () {
 timer=setInterval(autoPlay,2000);
 control.style.display="none";
};
//小圓點(diǎn)
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;
 }
}
//左右點(diǎn)擊
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");
};
//自動(dòng)輪播封裝
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)
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 淺談Javascript 數(shù)組與字典

    淺談Javascript 數(shù)組與字典

    這篇文章主要簡(jiǎn)單介紹了Javascript數(shù)組與字典,需要的朋友可以參考下
    2015-01-01
  • 利用原生JavaScript實(shí)現(xiàn)造日歷輪子實(shí)例代碼

    利用原生JavaScript實(shí)現(xiàn)造日歷輪子實(shí)例代碼

    這篇文章主要給大家介紹了關(guān)于如何利用原生JavaScript實(shí)現(xiàn)造日歷輪子的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用JavaScript具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • javascript表單正則應(yīng)用

    javascript表單正則應(yīng)用

    這篇文章主要為大家詳細(xì)介紹了javascript表單正則應(yīng)用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • js中的屏蔽的使用示例

    js中的屏蔽的使用示例

    本文為大家介紹下js中的屏蔽的應(yīng)用;屏蔽網(wǎng)頁內(nèi)容選中、剪切、復(fù)制及拷屏總之你能想象的應(yīng)該都有,感興趣的朋友可以參考下,希望對(duì)大家學(xué)習(xí)js有所幫助
    2013-07-07
  • 基于JavaScript概括瀏覽器方向的優(yōu)化

    基于JavaScript概括瀏覽器方向的優(yōu)化

    這篇文章主要介紹了JavaScript瀏覽器方向的優(yōu)化,文章圍繞主題展開詳細(xì)的內(nèi)容介紹具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-05-05
  • JS兩個(gè)數(shù)組比較,刪除重復(fù)值的巧妙方法(推薦)

    JS兩個(gè)數(shù)組比較,刪除重復(fù)值的巧妙方法(推薦)

    下面小編就為大家?guī)硪黄狫S兩個(gè)數(shù)組比較,刪除重復(fù)值的巧妙方法(推薦)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-06-06
  • js實(shí)現(xiàn)點(diǎn)擊文本框顯示日期選擇器特效代碼分享

    js實(shí)現(xiàn)點(diǎn)擊文本框顯示日期選擇器特效代碼分享

    這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)點(diǎn)擊文本框顯示日期選擇器特效,提高了工作效率,推薦給大家,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2015-08-08
  • 理解 JavaScript 預(yù)解析

    理解 JavaScript 預(yù)解析

    JavaScript是解釋型語言是毋庸置疑的,但它是不是僅在運(yùn)行時(shí)自上往下一句一句地解析的呢?
    2009-10-10
  • 如何制作幻燈片(代碼分享)

    如何制作幻燈片(代碼分享)

    本文主要分享了制作幻燈片的實(shí)例代碼,具有一定的參考價(jià)值,下面跟著小編一起來看下吧
    2017-01-01
  • JS 樹形遞歸實(shí)例代碼

    JS 樹形遞歸實(shí)例代碼

    下面的代碼是從實(shí)際項(xiàng)目中AJAX的回調(diào)部分 copy 出來的,使用了JS的遞歸,文本格式為JSON
    2010-05-05

最新評(píng)論