/* 浠g爜鏁寸悊锛氭噿浜轰箣瀹?www.lanrenzhijia.com */ (function($,window){ $.fn.focusbanner = function(options){ return this.each(function(){ var o = $.extend({},$.fn.focusbanner.options, options || {}), loopbody = $(o.loopbody), loops = loopbody.children(); if(loops.length <= 1) return; var dissolve = $(o.dissolve.selector), dischilds, discurclass = o.dissolve.curclass, control = $(o.control.selector), conchilds, concurclass = o.control.curclass, botton = $(o.botton.selector), btnchilds, btncurclass = o.botton.curclass, contentdiv = o.contentdiv, isloop = true, timer = null, ctimer = null, curclass = o.curclass, cell = 0, timedo = new date().gettime(), start = function() { cleartimeout(timer); timer = settimeout(autoplay,o.gap); isloop = true; }, stop = function() { cleartimeout(timer); isloop = false; }, autoplay = function() { jump('+'); }, jump = function(type,idx) { var c = loops,cur,next; if(idx === undefined) { cur = c.filter('.' + curclass); if(type === '+') { next = cur.next(); if(!next.length) next = c.eq(0); }else { next = cur.prev(); if(!next.length) next = c.eq(-1); } idx = next.index(); } move(type,idx); }, move = function(type,idx) { var i = 0, len = moves.length; do{ moves[i++](type,idx); } while(i < len); }, controlmove = function(type,idx) { conchilds.eq(idx).addclass(concurclass).siblings('.' + concurclass).removeclass(concurclass); }, loopmove = function(type,idx) { var currentloop = loops.filter('.' + curclass), nextloop = loops.eq(idx), left; if(type === '+') { nextloop.css('left',cell); left = '-' + cell+ 'px'; $(contentdiv).stop().css({left: 3600}); }else{ loopbody.css('left',-cell); currentloop.css('left',cell); nextloop.css('left',0); left = 0; $(contentdiv).stop().css({left: -3600}); } nextloop.addclass(curclass); timedo = new date().gettime(); loopbody.animate({ left: left },o.speed,'easeoutcirc',function(){ $(this).css('left',0); currentloop.removeclass(curclass); nextloop.css('left',0); if(isloop) start(); cleartimeout(ctimer); ctimer = settimeout(function() { $(contentdiv).animate({ left: 0 },o.speed,'easeoutcirc'); }, o.speed); }); }, dissolvemove = function(type,idx){ var currentdis = dischilds.filter('.' + discurclass), nextdis = dischilds.eq(idx); currentdis.animate({ opacity: 0},0,'linear',function(){ $(this).removeclass(discurclass); }); nextdis.animate({ opacity: 1},0,'linear',function(){ $(this).addclass(discurclass); }); }, bottonmove = function(type, idx){ var currentdis = btnchilds.filter('.' + btncurclass), nextdis = btnchilds.eq(idx); currentdis.animate({ opacity: 0},0,'linear',function(){ $(this).removeclass(btncurclass); }); nextdis.animate({ opacity: 1},0,'linear',function(){ $(this).addclass(btncurclass); }); }, resize = function(){ var lb = loopbody; cell = lb.parent().width(); loops.width(cell); lb.width(cell * 2); }, canmove = function(){ var now = new date().gettime(); if((now - timedo) < o.speed) return false; timedo = now; return true; }, bindconevent = function(e){ cleartimeout(timer); var t = $(e.target).closest(conchilds[0].tagname,this), nextidx,curidx,type; if(t.length && !t.is('.' + concurclass) && canmove()){ nextidx = t.index(); curidx = t.siblings('.' + concurclass).index(); type = nextidx > curidx ? '+' : '-'; isloop = false; jump(type,nextidx); } }, moves = [loopmove], setmoves = function(){ if(control.length){ conchilds = control.children(); control.bind('click',bindconevent); moves.push(controlmove); } if(dissolve.length){ dischilds = dissolve.children(); moves.push(dissolvemove); } if(botton.length){ btnchilds = botton.children(); moves.push(bottonmove); } }(); resize(); $(window).resize(resize); start(); $(this).hover(stop,start); if(o.prev){ $(o.prev).live('click',function(){ cleartimeout(timer); if(canmove()){ jump('-'); } return false; }); } if(o.next){ $(o.next).live('click',function(){ cleartimeout(timer); if(canmove()){ jump('+'); } return false; }); } }); }; $.fn.focusbanner.options = { loopbody: '', // 鐒︾偣鍥剧殑涓讳綋锛坰elector锛? curclass: 'current', // 鐒︾偣鍥惧綋鍓嶉€変腑鐨勬牱寮? speed:500, // 鐒︾偣鍥惧垏鎹㈢殑閫熷害锛堝崟浣嶏細ms锛? gap: 3000, // 鐒︾偣鍥惧垏鎹㈢殑闂撮殧锛堝崟浣嶏細ms锛? next: '', // 涓嬩竴寮犵劍鐐瑰浘鎸夐挳锛屽彲閫夛紙selector锛? prev: '', // 涓婁竴寮犵劍鐐瑰浘鎸夐挳锛屽彲閫夛紙selector锛? dissolve: { // 鍙岀劍鐐瑰浘鍒囨崲锛屽叾涓竴寮犵暐灏忕殑鍥句竴鑸細甯︿笂婧惰в鏁堟灉锛屽彲閫夈€傦紙娉細涓轰簡鍏煎浣庨厤缃満鍨嬶紝婧惰в鏁堟灉鐩墠鍙栨秷浜嗭紝鍙仛浜嗙畝鍗曠殑鍒囨崲銆傦級 curclass: 'current', selector: '' }, control: { // 鐒︾偣鍥惧甫鏈変笅鏍囩殑鍒囨崲锛屽彲閫? curclass: 'current', selector: '' }, botton: { // 鐒︾偣鍥惧甫鏈夋寜閽垏鎹? curclass: 'focus-btns', selector: '' }, contentdiv: 'content' }; })(jquery,window); (function($){ $(window).load(function(){ $('.focus-page-btn').show(); $('.f-content').show(); $('#banner_img').find('li').eq(0).addclass('on'); $('#banner_content').find('li').eq(0).addclass('on'); $('#banner_btn').find('a').eq(0).addclass('on'); $('.focus').focusbanner({ loopbody: '.f-img-list', dissolve: { selector: '.d-img-list', curclass: 'on' }, curclass: 'on', speed: 500, gap: 3000, next: '.focus-btn-next', prev: '.focus-btn-prev', contentdiv: '.f-content', botton: { selector: '.focus-btns', curclass: 'on' } }); }); })(jquery); /* 浠g爜鏁寸悊锛氭噿浜轰箣瀹?www.lanrenzhijia.com */