/** * slide (version 1.3) * @author lv ming (akm107@163.com) * * create a slide * @example new slide(container,options); * on jquery * */ function slide(container, options, callback){ this.container=$(container); this.list=$(container+' .j_slide_list'); this.handle=$(container+' .j_slide_trigger li'); this.item=$(container+' .j_slide_item'); this.itemwh=0; this.count=this.handle.length; this.timer=null; this.etime=null; this.options=$.extend({ auto:true, delay:4, duration:500, effect:'fade', event:'mouseover', firstdelay:null, index:1, vertical:true },options); this.init(); if(callback){ callback(); } } slide.prototype={ init:function(){ var slideclip, itemw, itemh, itemwh, that=this, list=this.list, item=this.item, op=this.options, auto=!!op.auto, vertical=!!op.vertical; if(op.effect==='fade'){ list.css({position:'relative'}); item.css({position:'absolute'}); } if(op.effect==='slide'){ list.css({position:'absolute'}); if(!list.parent().hasclass('j_slide_clip')){ list.wrap('
'); } itemw=item.outerwidth(true); itemh=item.outerheight(true); this.container.find('.j_slide_clip').css({position:'relative',overflow:'hidden',height:itemh,width:itemw}); this.itemwh=vertical?itemh:itemw; } this.handle.bind(op.event, this._trigger(this)); if(op.index>this.count||op.index<1){ op.index=1;}; this._showfirst(op.index); if(auto){ this._auto(op.firstdelay); this.container.hover(function(){that._stop();},function(){that._auto();}); } }, _trigger:function(o){ return function(e){ var index, op=o.options, handle=o.handle; if(op.index===(handle.index(this)+1)){ return; } index=op.index=handle.index(this)+1; o._show(index); }; }, _show:function(i){ var that=this, op=this.options, vertical=!!op.vertical; this.handle.removeclass('cur').eq(i-1).addclass('cur'); if(op.effect==='fade'){ cleartimeout(this.etime); this.etime=settimeout(function(){that.item.not(that).css({zindex:1}).eq(i-1).css({zindex:9}).animate({opacity:1},that.options.duration,function(){ that.item.not(this).css({opacity:0}) });},150); } if(op.effect==='slide'){ itemwh=this.itemwh; this.list.stop().animate({top:-itemwh*(i-1)},this.options.duration); } }, _showfirst:function(i){ var op=this.options, vertical=!!op.vertical; this.handle.removeclass('cur').eq(i-1).addclass('cur'); if(op.effect==='fade'){ this.item.not(this).css({zindex:1, opacity:0}).eq(i-1).css({zindex:9, opacity:1}); } if(op.effect==='slide'){ itemwh=this.itemwh; this.list.css({top:-itemwh*(i-1)}); } }, _auto:function(delay){ var that=this, op=that.options; this.timer=settimeout(function(){ op.index = op.index< that.count? ++op.index: 1; that._show(op.index); that._auto(); }, delay ? delay*1000 : op.delay*1000); }, _stop:function(){ cleartimeout(this.timer); } };