(编辑:jimmy 日期: 2024/12/23 浏览:2)
本文实例为大家分享了JavaScript实现原型封装轮播图的具体代码,供大家参考,具体内容如下
只要用dom元素调用这个方法,传一个数组进去,里面放的是图片的路径。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> * { padding: 0px; margin: 0px; list-style: none; } .leftBtn { position: absolute; width: 30px; height: 30px; color: black; background-color: cyan; top: 50%; margin-top: -15px; line-height: 30px; text-align: center; opacity: 0.6; cursor: pointer; left: 10px; } .rightBtn { position: absolute; width: 30px; height: 30px; color: black; background-color: cyan; top: 50%; margin-top: -15px; line-height: 30px; text-align: center; opacity: 0.6; cursor: pointer; right: 10px; } .slider { position: absolute; bottom: 20px; width: 100%; text-align: center; cursor: pointer; } .slider span { display: inline-block; width: 8px; height: 8px; background-color: darkgray; border-radius: 50%; margin-left: 10px; } .slider .active { background-color: #f40; } </style> </head> <body> <div class="div"></div> <div id="div"></div> <script> var div = document.getElementsByClassName('div')[0] var oDiv = document.getElementById('div') // var arr = ['./tp copy/decade.jpg', './tp copy/decad.jpg', './tp copy/tp.jpg'] HTMLDivElement.prototype.createTurnPage = function (arr) { var arr = (typeof arr != "object") "opacity") { cur = parseFloat(getStyle(dom, attr)) * 100; } else { cur = parseInt(getStyle(dom, attr)); } speed = (attrObj[attr] - cur) / 7; speed = speed < 0 "opacity") { dom.style.opacity = (speed + cur) / 100; } else { dom.style[attr] = speed + cur + "px"; } if (cur != attrObj[attr]) { stop = false; } } if (stop) { clearInterval(dom.timer); typeof callback == "function" && callback(); } }, 20); } </script> </body> </html>
精彩专题分享:jQuery图片轮播 JavaScript图片轮播 Bootstrap图片轮播
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。