/*----------------------------- list_fade_in -----------------------------*/ (function($){ var defaults = { activeIndex:0, autoExecute:false, timeAutoExecute:3000, pagerShow:true, speedFadeIn:500, speedAnimationHeight:500, funcFadeInSetFinishCallback:function(activeIndex){}, funcFadeInStartCallback:function(activeIndex){}, funcFadeInEndCallback:function(activeIndex){} }; $.fn.listFadeIn = function(options){ var configs = {}, el = this, lenEl = el.length, flagFuncExecute = true, timeAutoExecute = null, funcInit = function(){ configs = $.extend({}, defaults, options); var eleListFadeInUnorderedList = $('.list_fade_in_list', el), eleListFadeInContentsParent = $('.list_fade_in_contents_parent:eq(0)', el); if(configs.pagerShow){ $(eleListFadeInUnorderedList).show(); }else{ $(eleListFadeInUnorderedList).hide(); } funcImgLoad(eleListFadeInContentsParent, function(){ var eleListFadeInContentsActive = $('> .list_fade_in_contents', eleListFadeInContentsParent).eq(configs.activeIndex); $(eleListFadeInContentsActive).show(); funcAdjustmentHeight(function(){ if(configs.pagerShow){ var eleListFadeInList = $('.list_fade_in_list:eq(0) > li', el); eleListFadeInList.eq(configs.activeIndex).addClass('list_fade_in_active'); eleListFadeInList.each(function(){ var index = eleListFadeInList.index(this); $('> a', this) .eq(0) .on({ 'click':function(){ funcExecute(index); } }); }); } $(window).on({ 'resize':function(){ funcAdjustmentHeight(function(){}); } }); if(configs.autoExecute) funcSetAutoExecute(); funcCustomEvents(); funcDestructor(); configs.funcFadeInSetFinishCallback(configs.activeIndex); }); }); }, funcDestructor = function(){ lenEl = funcInit = funcCustomEvents = funcImgLoad = void 0; }, funcCustomEvents = function(){ el.on({ 'listFadeIn.funcListFadeInExecute':function(e, args){ funcExecute(args.index); }, 'listFadeIn.funcListFadeInAdjustmentHeight':function(e, callback){ if(typeof callback === 'undefined') callback = function(){}; funcAdjustmentHeight(callback); } }); }, funcImgLoad = function(ele, callback){ var count = 0, eleImg = ele.find('img'), lenImg = $(eleImg).length; if(lenImg === 0) callback(); $(eleImg).each(function(){ var eleImg = $(''); eleImg.on({ 'load':function(){ count++; if(lenImg === count) callback(); }, 'error':function(){ count++; if(lenImg === count) callback(); } }); eleImg.attr('src', $(this).attr('src')); }); }, funcAdjustmentHeight = function(callback){ var eleListFadeInContentsParent = $('.list_fade_in_contents_parent:eq(0)', el), eleListFadeInContentsCurrent = $('> .list_fade_in_contents', eleListFadeInContentsParent).eq(configs.activeIndex); eleListFadeInContentsParent .stop() .animate( { 'height':eleListFadeInContentsCurrent.outerHeight(true) + 'px' }, configs.speedAnimationHeight, function(){ callback(configs.activeIndex); } ); }, funcSetAutoExecute = function(){ var eleListFadeInContentsParent = $('.list_fade_in_contents_parent:eq(0)', el), eleListFadeInContents = $('> .list_fade_in_contents', eleListFadeInContentsParent); timeAutoExecute = setTimeout(function(){ var nextIndex = configs.activeIndex + 1; funcExecute(nextIndex === eleListFadeInContents.length?0:nextIndex); }, configs.timeAutoExecute + configs.speedFadeIn); }, funcExecute = function(index){ if( flagFuncExecute === false || configs.activeIndex === index ) return false; flagFuncExecute = false; configs.funcFadeInStartCallback(configs.activeIndex); if( configs.autoExecute && typeof timeAutoExecute === 'number' ){ clearTimeout(timeAutoExecute); timeAutoExecute = void 0; } var eleListFadeInContentsParent = $('.list_fade_in_contents_parent:eq(0)', el), eleListFadeInContentsActivePrev = $('> .list_fade_in_contents', eleListFadeInContentsParent).eq(configs.activeIndex), eleListFadeInContentsActiveNext = $('> .list_fade_in_contents', eleListFadeInContentsParent).eq(index); eleListFadeInContentsActivePrev .css({ 'z-index':'0' }); eleListFadeInContentsActiveNext .css({ 'z-index':'1' }) .fadeIn( configs.speedFadeIn, function(){ eleListFadeInContentsActivePrev.hide(); $('.list_fade_in_list:eq(0) > li', el).eq(configs.activeIndex).removeClass('list_fade_in_active'); configs.activeIndex = index; $('.list_fade_in_list:eq(0) > li', el).eq(configs.activeIndex).addClass('list_fade_in_active'); funcAdjustmentHeight(function(){ flagFuncExecute = true; if(configs.autoExecute) funcSetAutoExecute(); configs.funcFadeInEndCallback(configs.activeIndex); }); } ); }; if(lenEl === 0)return this; if(lenEl > 1){ el.each(function(){$(this).listFadeIn(options)}); return this; } funcInit(); }; })(jQuery); /*----------------------------- /list_fade_in -----------------------------*/