JavaScript部分
(function(window,document) { var Broadcast = function(cla,options) { // 判断是用函数创建的还是用new创建的。这样我们就可以通过Broadcast("dom") 或 new Broadcast("dom")来使用 if (!(this instanceof Broadcast)) return new Broadcast(cla, options); // 排序图片的层叠位置 var front = this.nameclass(cla),//获取的class元素组 img = this.childer(front), imglength = img.length, jishu = 0, _this = this,intr; for (var r in img) { if (r == 0) { img[r].style.cssText= 'z-index:' + (imglength - r) + ';position:absolute;opacity:1;transition:0.5s;'; } else { img[r].style.cssText= 'z-index:' + (imglength - r) + ';position:absolute;opacity:0;transition:0.5s;'; } } //设置选择器 if(options.spot=="true"){ if(options.Selector!=undefined){ for(var i=0;i
HTML结构部分
CSS部分
.boy{ width: 1103px; margin: 0 auto; height: 714px; position: relative;}.img-box{ height: 714px;}.img-box a{ float: left;}/* 设置圆点的样式 */.selector{ width: 96px; position: absolute; left: 50%; margin-left: -48px; bottom: 20px; z-index: 222;}.selector span{ float: left; margin-left: 10px; border-radius: 100px; background-color: #999; width: 14px; height: 14px; cursor: pointer;}.selector .current-dan{ background-color: #13af13;}/* 设置箭头的位置 */.left-att{ position: absolute; left: 20px; margin-top: -20px; top: 50%; width: 40px; height: 40px; background: rgba(0, 0, 0, 0.5); color: #fff; text-align: center; line-height: 40px; font-weight: bold; z-index: 222; cursor: pointer;}.right-att{ position: absolute; right: 20px; margin-top: -20px; top: 50%; width: 40px; height: 40px; background: rgba(0, 0, 0, 0.5); color: #fff; text-align: center; line-height: 40px; font-weight: bold; cursor: pointer; z-index: 222;}
调用方法
var ip = new Broadcast('boy',{ //轮播图整体结构的父级class spot:'true',//false不需要选择器true设置选择器 Selector:'selector',//设置你选这器的父级名称 current:'current-dan', //设置当前选择的圆点class leftarrow:'left-att',//设置左箭头class rightarrow:'right-att'//设置右箭头clas });