// javascript document var glume = function(banners_id, focus_id){ this.$ctn = $('#' + banners_id); this.$focus = $('#' + focus_id); this.$adlis = null; this.$btns = null; this.switchspeed = 3;//自动播放间隔(s) this.defopacity = 1; this.crtindex = 0; this.adlength = 0; this.timerswitch = null; this.init(); }; glume.prototype = { fnnextindex:function(){ return (this.crtindex >= this.adlength-1)?0:this.crtindex+1; }, //动画切换 fnswitch:function(toindex){ if(this.crtindex==toindex){return;} this.$adlis.css('zindex', 0); this.$adlis.filter(':eq('+this.crtindex+')').css('zindex', 2); this.$adlis.filter(':eq('+toindex+')').css('zindex', 1); this.$btns.removeclass('on'); this.$btns.filter(':eq('+toindex+')').addclass('on'); var me = this; $(this.$adlis[this.crtindex]).animate({ opacity: 0 }, 1000, function() { me.crtindex = toindex; $(this).css({ opacity: me.defopacity, zindex: 0 }); }); }, fnautoplay:function(){ this.fnswitch(this.fnnextindex()); }, fnplay:function(){ var me = this; me.timerswitch = window.setinterval(function() { me.fnautoplay(); },me.switchspeed*1000); }, fnstopplay:function(){ window.cleartimeout(this.timerswitch); this.timerswitch = null; }, init:function(){ this.$adlis = this.$ctn.children(); this.$btns = this.$focus.children(); this.adlength = this.$adlis.length; var me = this; //点击切换 this.$focus.on('click', 'a', function(e) { e.preventdefault(); var index = parseint($(this).attr('data-index'), 10) me.fnswitch(index); }); this.$adlis.filter(':eq('+ this.crtindex +')').css('zindex', 2); this.fnplay(); //hover时暂停动画 this.$ctn.hover(function() { me.fnstopplay(); }, function() { me.fnplay(); }); if($.browser.msie && $.browser.version < 7) { this.$btns.hover(function() { $(this).addclass('hover'); },function() { $(this).removeclass('hover'); }); } } }; var player1 = new glume('_banners', '_focus');