; (function () { var time = null; var slider = function (options) { this.osliderwrap = options.osliderwrap; this.slideritems = options.slideritems; this.sliderlen = this.slideritems.length; this.yuan = options.yuan; this.yuanitems = options.yuanitems; this.btngroupleft = options.btngroupleft; this.btngroupright = options.btngroupright; this.idx = 0; } $.extend(slider.prototype, { init: function () { this.bindevent(); this.autoplay(); }, bindevent: function () { this.osliderwrap.on('mouseenter', this.mousein); this.osliderwrap.on('mouseleave', $.proxy(this.mouseout, this)); this.yuan.on('mouseenter', ".yuan-item", $.proxy(this.manslider, this)); this.btngroupleft.on('click', $.proxy(this.handlebtnleft, this)); this.btngroupright.on('click', $.proxy(this.handlebtnright, this)) }, //自动轮播 autoplay: function () { time = setinterval(this.nextslide.bind(this), 4000); }, //鼠标移入,清除定时器 mousein: function () { clearinterval(time); }, //鼠标移入,启动定时器 mouseout: function () { this.autoplay(); }, nextslide: function () { if (this.idx >= this.sliderlen - 1) { this.idx = 0; } else { this.idx++; } this._slideaction(this.idx); }, prevslide: function () { if (this.idx <= 0) { this.idx = this.sliderlen - 1; } else { this.idx--; } this._slideaction(this.idx); }, howslidermove(things) { switch (things) { case 'left': this.prevslide(); break; case 'right': this.nextslide(); break; } }, handlebtnleft: function () { this.howslidermove('left') }, handlebtnright: function () { this.howslidermove('right') }, //小圆点对应图片 manslider: function (e) { var e = e || window.event; var tar = e.target || e.srcelement; var tagname = tar.tagname.tolowercase(); if (tagname === "i") { this.idx = array.prototype.indexof.call(this.yuanitems, tar); //index的位置 this._slideaction(this.idx); } }, //图片切换 _slideaction: function (idx) { this.slideritems.eq(idx).stop().fadein(1000) .siblings().stop().fadeout(1000); this.yuanitems.eq(idx).addclass('cur') .siblings().removeclass('cur'); }, }); window.slider = slider; })();