; (function ($) { var fadeslide = function (carousel) { var self = this; this.carousel = carousel; this.setting = { "pictures": ".banner li", "indexs": ".bannerindex dd", "btnprev": ".prev", "btnnext": ".next", "infos": ".title p", "autoplay": true, "delay": 5000 }; $.extend(this.setting, this.getsetting()); this.itempics = carousel.find(this.setting.pictures); this.itemindexs = carousel.find(this.setting.indexs); this.iteminfos = carousel.find(this.setting.infos); this.prevbtn = carousel.find(this.setting.btnprev); this.nextbtn = carousel.find(this.setting.btnnext); this.piclens = this.itempics.length; this.delay = this.setting.delay; this.timer = 0; this.cindex = 0; this.pindex = -1; this.citempic = this.itempics.eq(this.cindex); this.citemindex = this.itemindexs.eq(this.cindex); this.setdefault(); if (this.piclens > 1) { this.gofade() } this.prevbtn.click(function () { self.gofade(self.indexreduce()) }); this.nextbtn.click(function () { self.gofade(self.indexadd()) }); this.itemindexs.hover(function () { self.cindex = $(this).index(); if (self.cindex === self.pindex) return; self.gofade(self.cindex) }); this.carousel.hover(function () { cleartimeout(self.timer) }, function () { self.autoplay() }) }; fadeslide.prototype = { autoplay: function () { var self = this; this.timer = settimeout(function () { self.gofade(self.indexadd()) }, this.delay) }, gofade: function (cindex) { cleartimeout(this.timer); this.pindex = this.cindex; this.citempic.stop(false, true).fadeout(800); this.citempic = this.itempics.eq(this.cindex).stop(false, true).fadein(800); this.citemindex.removeclass("on"); this.citemindex = this.itemindexs.eq(this.cindex).addclass("on"); this.iteminfos.hide(); this.iteminfos.eq(this.cindex).fadein(400); if (this.piclens > 1) { this.autoplay() } }, setdefault: function () { this.itempics.first().show(); if (this.itemindexs.length == 1) { this.citemindex.hide(); this.prevbtn.hide(); this.nextbtn.hide() } }, indexadd: function () { return (this.cindex === this.piclens - 1) ? this.cindex = 0 : ++this.cindex }, indexreduce: function () { return (this.cindex === 0) ? this.cindex = this.piclens - 1 : --this.cindex }, getsetting: function () { var setting = this.carousel.attr("data-setting"); if (setting && setting != "") { return $.parsejson(setting) } else { return {} } } }; fadeslide.init = function (dom) { var _this_ = this; dom.each(function () { new _this_($(this)) }) }; window["fadeslide"] = fadeslide })(jquery);