/** * author hkuclion * hkuclion@163.com */ (function($){ //below jquery 1.7; if(!$.fn.prop)$.fn.prop=$.fn.attr; $.fn.hkuc_fs_trans=function(opt){ return new $.hkuc_fs_trans(this,opt); } var defaults={ 'auto':5000,//自动间隔时间 'duration':800,//切换花费时间 'container':'ul',//container标签 'element':'li',//container的子级选择器 'buttonprev':null,//null,jquery选择器 'buttonnext':null,//null,jquery选择器 'shownumber':true,//true,jquery选择器 'buttonnumer':'
{$index}
',//{$index}会被替换为为当前页码,此为false时不自动生成页码链接,使用shownumber的子元素作为页码 //to:function 'numbercallback':true,//true,自定义函数,具体写法见hkuc_fs_refresh_number,此为true时的默认处理函数 'transcallback':null, 'numbercurrentclass':'current',//当前页码的class 'numberevent':'click',//click,页面的事件 'pause':true,//在移上时是否暂停 'zindex':1000,//基础zindex,内容zindex,当前内容为zindex+1,页码为zindex+2 'type':'slide',//slide,fade 'cacheimage':false,//是否在图片读取完成后才显示 'loading':false,//在读取过程中显示的图片 'cachetimeout':10000,//读取超过多少时间后放弃读取,直接显示 'adjustheight':false,//根据内容最高高度将所有元素高度调整为统一高度 'stopanimation':false,//如果进入新的事件则停止已经存在的动画 'fscode':false,//全屏时加入代码结构 'dummy':'dummy' }; $.hkuc_fs_trans=function(wrapper,opt){ var cache=this.cache=[]; cache['this']=this; this.options = $.extend({}, defaults, opt || {}); this.locked = false; this.$wrapper = null; this.$container = null; this.$elements = null; this.buttonnext = null; this.buttonprev = null; this.$wrapper = $(wrapper); if(this.$wrapper.is(this.options['container'])){ this.$container=this.$wrapper; this.$wrapper=this.$container.parent(); } else{ this.$container=this.$wrapper.children(this.options['container']); } if(typeof(this.options['numbercallback'])!='function'){this.options['numbercallback']=hkuc_fs_refresh_number;} if(typeof(this.options['transcallback'])!='function'){this.options['transcallback']=null;} this.$wrapper.data('this',this); if(this.options['cacheimage']) this.$container.css('visibility','hidden'); this.$elements = this.$container.find(this.options['element']); this.length = this.$elements.size(); this.$wrapper.css({ 'width':'100%', 'overflow':'hidden', 'position':'relative','z-index':cache['this'].options.zindex }).addclass('hkuc_fs_trans'); this.$container.css({ 'position':'relative','z-index':cache['this'].options.zindex }); this.$elements.each(function(index){ switch(cache['this'].options.type){ case 'fade': $(this).css({ 'width':'100%', 'overflow':'hidden', 'left':0, 'position':'absolute','z-index':(index?cache['this'].options.zindex:cache['this'].options.zindex+1) }); if(index!=0)$(this).hide(); break; case 'slide': default: $(this).css({ 'width':'100%', 'overflow':'hidden', 'left':'0%', 'position':'absolute','z-index':(index?cache['this'].options.zindex:cache['this'].options.zindex+1) }); } if(cache['this'].options.fscode){ $(this).html('
'+$(this).html()+'
'); $(this).css({ height:cache['this'].$wrapper.height() }) } }) cache['image_srcs']=[]; this.$elements.find('img').each(function(index){ cache['image_srcs'][index]=$(this).attr('src'); }) cache['image_count']=cache['image_srcs'].length; cache['image_ready_count']=0; cache['element_count']=this.$elements.length; cache['image_objs']=[]; cache['image_sizes']=[]; if(this.options['cacheimage'] && cache['image_count']){ for(var i=0; i'+(this.options['loading']?'':'')+' 读取中 0/'+cache['image_count']+' ...'); cache['image_cache_timeout']=window.settimeout($.proxy(function(){ $(this.cache['image_objs']).unbind('load'); cache['this'].$wrapper.find('.loading').hide(); $.hkuc_fs_trans_init.call(this); },this),this.options['cachetimeout']); } else{ $.hkuc_fs_trans_init.call(cache['this']); } } $.hkuc_fs_trans_init=function(){ var cache=this.cache; if(this.options['adjustheight']){ var _maxheight=0; this.$elements.each(function(){ var cur_height=$(this).height(); if(cur_height>_maxheight) _maxheight=cur_height; }); this.$elements.height(_maxheight); this.$wrapper.height(_maxheight); } if(this.options['shownumber']){ if(this.options['shownumber']===true){ var numberstr='
'; this.$wrapper.append($(numberstr)); var $numberwrapper=this.$wrapper.find('.hkuc_fs_number'); this.$wrapper.find('.hkuc_fs_number_wrap').css('z-index',this.options['zindex']+1); } else{ var $numberwrapper=$(this.options['shownumber']); } $numberwrapper.css('z-index',this.options['zindex']+1); if(this.options['buttonnumer']){ var number_tag=$(this.options['buttonnumer']).prop('nodename').tolowercase(); numberstr=''; for(var i=0; i=0 && param['index']<=cache['element_count']){ cache['next']=param['index']; } } window.cleartimeout(cache['transtimeout']); } if(this.options.type=='fade'){ var $current=this.$elements.eq(cache['current']); var $next=this.$elements.eq(cache['next']); if(cache['current']==cache['next']){ cache['next']=(cache['current']+1)%cache['element_count']; cache['prev']=(cache['element_count']+cache['current']-1)%cache['element_count']; } } if(cache['current']==cache['next']){ cache['lock']=false; return; } var org_active=cache['current']; cache['current']=cache['next']; if(this.options.type=='fade'){ $next.show(); $current.fadeout(this.options.duration,jquery.proxy(function(){ this.$elements.css('z-index',cache['this'].options['zindex']); $next.css('z-index',cache['this'].options['zindex']+1); if(this.options['auto'] && (!this.options['pause'] || !cache['hover'])){ this.cache['transtimeout']=window.settimeout(jquery.proxy(hkuc_fs_trans_to,this),this.options['auto']); } this.cache['lock']=false; },this) ) } else{ var dir; if(param.index=='next')dir='next'; else if(param.index=='prev')dir='prev'; else{ if(cache['current'] > org_active)dir='next'; else if(cache['current'] < org_active)dir='prev'; else dir='next'; } if(dir=='next'){ this.$elements.eq(org_active).css({'left':'0%'}); this.$elements.eq(cache['current']).css({'left':'100%'}); this.$container.animate( { 'left' : '-100%' }, this.options.duration, jquery.proxy(function(){ if(this.options['auto'] && (!this.options['pause'] || !cache['hover'])){ this.cache['transtimeout']=window.settimeout(jquery.proxy(hkuc_fs_trans_to,this),this.options['auto']); } this.$container.css({'left':'0%'}); this.$elements.eq(cache['current']).css({'left':'0%','z-index':cache['this'].options['zindex']+1}); this.$elements.eq(org_active).css({'z-index':cache['this'].options['zindex']}); this.cache['lock']=false; },this) ); } else if(dir=='prev'){ this.$elements.eq(org_active).css({'left':'0%'}); this.$elements.eq(cache['current']).css({'left':'-100%'}); this.$container.animate( { 'left' : '100%' }, this.options.duration, jquery.proxy(function(){ if(this.options['auto'] && (!this.options['pause'] || !cache['hover'])){ this.cache['transtimeout']=window.settimeout(jquery.proxy(hkuc_fs_trans_to,this),this.options['auto']); } this.$container.css({'left':'0%'}); this.$elements.eq(cache['current']).css({'left':'0%','z-index':cache['this'].options['zindex']+1}); this.$elements.eq(org_active).css({'z-index':cache['this'].options['zindex']}); this.cache['lock']=false; },this) ); } } if(this.options['shownumber']){ var $currentnumber=this.$number.filter('.'+this.options['numbercurrentclass']); var $targetnumber=this.$number.eq(cache['current']); this.options['numbercallback'].call(this,$currentnumber,$targetnumber); } if(this.options['transcallback']){ this.options['transcallback'].call(this,org_active,cache['current']); } cache['next']=(cache['current']+1)%cache['element_count']; cache['prev']=(cache['element_count']+cache['current']-1)%cache['element_count']; } var hkuc_fs_refresh_number=function($currentnumber,$targetnumber){ $currentnumber.removeclass(this.options['numbercurrentclass']); $targetnumber.addclass(this.options['numbercurrentclass']); } })(jquery);