日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

js實(shí)現(xiàn)無(wú)縫連接輪播圖(四)點(diǎn)擊小圓點(diǎn),移動(dòng)圖片

 python_lover 2021-09-11

<!-- 這個(gè)animate.js 必須寫到 index.js的上面引入 -->
<script src="js/animate.js"></script>
<!-- 引入我們首頁(yè)的js文件 -->
<script src="js/index.js"></script>

 

HTML代碼

------------------------------------------------------

<div class="focus fl">
<!-- 左側(cè)按鈕 -->
<a href="javascript:;" class="arrow-l">
<
</a>
<!-- 右側(cè)按鈕 -->
<a href="javascript:;" class="arrow-r"> ? </a>
<!-- 核心的滾動(dòng)區(qū)域 -->
<ul>
<li>
<a href="#"><img src="upload/focus.jpg" alt=""></a>
</li>
<li>
<a href="#"><img src="upload/focus1.jpg" alt=""></a>
</li>
<li>
<a href="#"><img src="upload/focus2.jpg" alt=""></a>
</li>
<li>
<a href="#"><img src="upload/focus3.jpg" alt=""></a>
</li>
</ul>
<!-- 小圓點(diǎn) -->
<ol class="circle">

</ol>
</div>

------------------------------------------------

js代碼

----------------------------------------------------------------------

window.addEventListener('load’,function(){

//1、獲取元素

var arrow-l = document.querySelector('.arrow-l’);

var arrow-r = document.querySelector('.arrow-r’);

var focus = document.querySelector('.focus’);

var focuwidth = focus.offsetWidth;

focus.addEventListener('mouseenter’,function(){

  arrow-l.style.display = 'block’;

  arrow-r.style.display = 'block’;

});

focus.addEventListener('mouseleave’,function(){

  arrow-l.style.display = 'none’;

  arrow-r.style.display ='none’;

});

 

//2、動(dòng)態(tài)生成小圓點(diǎn)

var ul = focus.querySelector('ul’);

var ol = focus.querySelector('ol’);

for(var i = 0;i<ul.children.length;i++){  //使用for循環(huán),根據(jù)banner圖片的數(shù)量生成li小圓點(diǎn)的數(shù)量

  var i = document.createElement('li’); 

  li.setAttribute('index’,i);

  ol.appendChild(li);

//3.在小圓點(diǎn)生成的同時(shí),用排他思想并且綁定點(diǎn)擊事件實(shí)現(xiàn)顏色填充的切換

  li.addEventListener('click’,function(){ //再點(diǎn)擊事件里使用for循環(huán)的排他思想

  //清除掉所有l(wèi)i里面的current

  for(var i = 0;i<ol.children.length;i++){

    ol.children[i].className = '’;

  }

  this.className = 'current’;

  var index = this.getAttribute('index’);  //聲明一個(gè)變量,存儲(chǔ)點(diǎn)擊獲得的自定義的屬性

  animate(ul, -index*focusWidth); //調(diào)用動(dòng)畫函數(shù),傳入實(shí)參ul,移動(dòng)的距離是小圓點(diǎn)的索引*圖片的寬度(必須是負(fù)值);

  })

}

  ol.children[0] = 'current’;

 

})

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多