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

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

js實現輪播圖制作方法

瀏覽:93日期:2024-03-22 14:48:00

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

效果如圖所示

js實現輪播圖制作方法

代碼如下:

<!DOCTYPE html><html> <head> <meta charset='utf-8' /> <title></title> <style type='text/css'> * { padding: 0; margin: 0; } .container { position: relative; width: 600px; height: 300px; margin: 30px auto; overflow: hidden; } .left { display: none; position: absolute; top: 50%; left: -20px; transform: translateY(-50%); width:50px; height: 50px; border-top-right-radius: 50%; border-bottom-right-radius: 50%; background-color: rgba(0,0,0,0.5); z-index: 999; } .left i { display: block; margin-top: 10px; margin-left: 20px; width: 30px; height: 30px; background: url(img/left.png) no-repeat; background-size: 30px 30px; } .right { display: none; position: absolute; top: 50%; right: -20px; transform: translateY(-50%); width:50px; height: 50px; border-top-left-radius: 50%; border-bottom-left-radius: 50%; background-color: rgba(0,0,0,0.5); z-index: 999; } .right i { display: block; margin-top: 10px; margin-right: 20px; width: 30px; height: 30px; background: url(img/right.png) no-repeat; background-size: 30px 30px; } ul li,ol li { list-style: none; } .picture { position: absolute; } .list { position: absolute; bottom: 10px; left: 10px; } .list li { float: left; margin-right: 10px; width: 10px; height: 10px; border-radius: 10px; background-color: rgba(0,0,0,0.5); cursor: pointer; } .list .current { background-color: #fff; } .picture li { position: absolute; width: 600px; height: 300px; } img { width: 100%; height: 100%; } </style> </head> <body> <div class='container'> <span class='left'><i></i></span> <span class='right'><i></i></span> <ul class='picture'> <li><img src='http://www.cgvv.com.cn/bcjs/img/1.jpg' ></li> <li><img src='http://www.cgvv.com.cn/bcjs/img/2.jpg' ></li> <li><img src='http://www.cgvv.com.cn/bcjs/img/3.jpg' ></li> <li><img src='http://www.cgvv.com.cn/bcjs/img/4.jpg' ></li> <li><img src='http://www.cgvv.com.cn/bcjs/img/5.jpg' ></li> </ul> <ol class='list'> </ol> </div> <script type='text/javascript'> var picture = document.querySelector(’.picture’); var list = document.querySelector(’.list’); var num=0; var circle=0; for (i=0;i<picture.children.length;i++) { // 設置圖片的位置 picture.children[i].style.left = i*600 + ’px’; // 自動生成有序列表 var li = document.createElement(’li’); li.setAttribute(’index’,i);list.appendChild(li); // 給li添加點擊事件 li.addEventListener(’click’,function () { for (var i=0;i<list.children.length;i++) { list.children[i].className = ’’; } this.className = ’current’; var index = this.getAttribute(’index’); num = index; circle = index; animate(picture,-index*600); }) } // 設置第一個ol孩子的類名 list.children[0].className = ’current’; var left = document.querySelector(’.left’); var right = document.querySelector(’.right’); var container = document.querySelector(’.container’); // 設置鼠標經過離開事件 container.addEventListener(’mouseover’,function () { left.style.display = ’block’; right.style.display = ’block’; clearInterval(timer) timer = null; }) container.addEventListener(’mouseleave’,function () { left.style.display = ’none’; right.style.display = ’none’; timer = setInterval(function () { right.click(); },1000); }) // js動畫函數 function animate (obj,target,callback) { clearInterval(obj.timer) obj.timer = setInterval(function () { var step = (target - obj.offsetLeft)/10; step = step > 0 ? Math.ceil(step) : Math.floor(step); if(obj.offsetLeft == target) { clearInterval(obj.timer); if (callback) { callback(); } } obj.style.left = obj.offsetLeft + step + ’px’; },15) } var first = picture.children[0].cloneNode(true); picture.appendChild(first); picture.lastChild.style.left = (picture.children.length-1)*600 + ’px’; //右側點擊事件 right.addEventListener(’click’,function () { if (num==picture.children.length-1) { picture.style.left = 0; num = 0; } num++; animate(picture,-num*600); circle ++; if (circle == list.children.length) { circle = 0; }for (var i = 0;i<list.children.length;i++) { list.children[i].className = ’’; } list.children[circle].className = ’current’; }) // 左側點擊事件 left.addEventListener(’click’,function () { if (num==0) { picture.style.left = -(picture.children.length-1)*600 +’px’; num = picture.children.length-1; } num--; animate(picture,-num*600); circle --; if (circle < 0) { circle = list.children.length-1; }for (var i = 0;i<list.children.length;i++) { list.children[i].className = ’’; } list.children[circle].className = ’current’; }) var timer = setInterval(function () { // 手動調用 right.click(); },1000); </script> </body></html>

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

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 干欧美女人| 日本一区二区不卡久久入口 | 国产一级性片 | 一级毛片免费在线观看网站 | 男人精品一线视频在线观看 | 美女全黄视频 | 久久久久久免费观看 | 一区二区三区视频观看 | 91av综合| 久久综合香蕉久久久久久久 | 亚洲国产2017男人a天堂 | 国产精品成人在线播放 | 中文字幕日韩精品亚洲七区 | 一级美女片 | 另类专区国产在线视频 | 日韩成人毛片高清视频免费看 | 欧美日韩精品一区二区三区视频 | 成人一级黄色毛片 | 中文字幕国产一区 | 步兵社区在线观看 | 国产一区二三区 | 欧美一级特黄aaaaaa在线看片 | 一区二区在线欧美日韩中文 | 日韩美一区二区三区 | 九九精品视频在线观看 | 亚洲欧美日本国产综合在线 | 中国国产成人精品久久 | 伊人久久精品午夜 | 久久97视频 | 欧美激情性色生活片在线观看 | 日韩欧美一级a毛片欧美一级 | 国产成人精品亚洲777图片 | 国产午夜亚洲精品一区网站 | 成人性色大片 | 最新国产美女肝交视频播放 | 精品国产亚洲人成在线 | 农村三级孕妇视频在线 | 免费久久精品 | 免费一级a毛片在线播放视 免费一级α片在线观看 | 蜜臀91精品国产高清在线观看 | 国产激情视频在线播放 |