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

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

JS輪播圖的實現方法2

瀏覽:71日期:2024-04-24 09:48:00

本文實例為大家分享了JS輪播圖的實現代碼,供大家參考,具體內容如下

需求:

自動輪播,鼠標移入輪播停止、移出繼續,小圓點點擊切圖,左右箭頭切圖

效果圖:

![輪播圖]

JS輪播圖的實現方法2

思路:

JS輪播圖的實現方法2

將所有需要輪播的圖片橫向排列,可視區大小設置為只能顯示一張圖片,給容器設置移出隱藏后,可視區之外的部分被隱藏,這樣我們就只能看見一張圖片。輪播實現是改變整個圖片畫幅的left值或者margin-left 值,當點擊時移動整個畫幅單個圖片的寬度即可實現滾動到下一張。后面功能實現順序依舊是寫法一里的思路。

戳!寫法一地址

HTML部分:

<div id='banner'> <div class='w'><!-- 左右箭頭--> <span class='iconfont icon-zuojiantou'></span> <span class='iconfont icon-youjiantou'></span><!-- 輪播圖--> <ul > <li><img src='http://www.cgvv.com.cn/bcjs/img/1.jpg' alt=''></li> <li><img src='http://www.cgvv.com.cn/bcjs/img/2.jpg' alt=''></li> <li><img src='http://www.cgvv.com.cn/bcjs/img/3.jpg' alt=''></li> </ul><!-- /小圓點--> <ol id='circleContainer'> </ol> </div></div>

CSS部分:

<style> *{ margin: 0; padding: 0; list-style: none; } .w { width: 1000px; height: 600px; margin: 100px auto 0; position: relative; overflow: hidden; } ul { width: 1000%; transition: all .5s ease-in-out; } ul li { float: left; width: 1000px; } ul li img { width: 100%; height: 600px; } .iconfont { color: white; position: absolute; font-size: 30px; top: calc(50% - 15px); background-color: rgba(216, 216, 216, 0.23); border-top-right-radius: 50%; border-bottom-right-radius: 50%; cursor: pointer; } .iconfont:hover { color: palegreen; } .icon-zuojiantou { left: 0; } .icon-youjiantou { right: 0; } #circleContainer { position: absolute; bottom: 10px; left: calc(50% - 30px); } #circleContainer li { display: inline-block; width: 20px; height: 20px; border-radius: 50%; background-color: white; margin-right: 5px; } #circleContainer .change { background-color: palegreen; }</style>

JS部分:

<script> let timer = setInterval(function () { arrow_r.onclick(); },2000); let w = document.querySelector('.w'); w.addEventListener('mouseenter',function () { clearInterval(timer); }); w.addEventListener('mouseleave',function () { clearInterval(timer); timer = setInterval(function () { arrow_r.onclick(); },2000); }); //獲取元素 let ul = document.querySelector('ul'); let ol = document.querySelector('#circleContainer'); let arrow_r = document.querySelector('.icon-youjiantou'); let arrow_l = document.querySelector('.icon-zuojiantou'); let ImgWidth = ul.children[0].offsetWidth; let location_i = 0 ; // 創建小圓點 動態生成小圓點,圖片增加時小圓點也隨之增加 for (let i = 0; i<ul.children.length;i++){ let li = document.createElement('li'); li.setAttribute('index',i); li.addEventListener('click',function () { let index = this.getAttribute('index'); move(ul,index); location_i = index ; }); ol.appendChild(li); } let liclone = ul.children[0].cloneNode(true); ul.appendChild(liclone); // 輪播函數 function move(targetObj,n) { if (n === targetObj.children.length ) { targetObj.style.marginLeft = '0px'; n = 0; } targetObj.style.marginLeft = -n * ImgWidth +'px'; for (let i =0 ;i<ol.children.length;i++){ ol.children[i].className = ''; } n === 3 ? ol.children[0].className = 'change': ol.children[n].className = 'change'; } ol.children[0].className = 'change'; // 右箭頭點擊 arrow_r.onclick = function () { if (location_i === 3) { location_i = 0 ; ul.style.marginLeft = '0px' ; } location_i++; move(ul,location_i); }; // 左箭頭點擊 arrow_l.addEventListener('click',function () { if (location_i == 0) { location_i = ul.children.length -1 ; } location_i--; move(ul,location_i); })</script>

精彩專題分享:jQuery圖片輪播 JavaScript圖片輪播 Bootstrap圖片輪播

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

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 手机在线观看黄色网址 | 曰本黄大片 | 国产成人不卡亚洲精品91 | 国产亚洲欧美在线视频 | 看真人视频一级毛片 | 久久九九热视频 | 92精品国产自产在线观看 | 天堂mv亚洲mv在线播放9蜜 | 免费看黄网址 | 成人三级视频在线观看 | 超清国产粉嫩456在线免播放 | 俄罗斯美女在线观看一区 | 亚洲韩精品欧美一区二区三区 | 女人张开腿给人桶免费视频 | 欧美一级特黄高清免费 | 欧美成人私人视频88在线观看 | 欧美黑大粗硬毛片视频 | 欧美黄网在线 | 天天干夜夜怕 | 女人毛片a毛片久久人人 | 日本在线视频免费看 | 欧美片a| 国产在线精品观看 | 成人免费ā片 | a亚洲| 深夜福利视频在线观看 | 精品国产一区二区三区在线 | 免费毛片视频网站 | 日韩三级在线观看视频 | 欧美色xxxx| 国产免费人视频在线观看免费 | 生活片一级播放免费 | 欧美多人三级级视频播放 | 一级毛片免费在线播放 | 亚洲另类激情综合偷自拍图 | 成人久久18免费游戏网站 | 羞羞一区二区三区四区片 | 成人公开免费视频 | 一区二区三区四区五区六区 | 久久国产精品久久国产精品 | 国产色啪午夜免费视频 |