/* * jquery图片轮播(焦点图)插件 * add.jena.201206291027 * edit.jena.201206300904 * edit.jena.201207051027 * edit.jena.201208090849 * edit.jena.201501231440 * version: 2.2.1440 * author: jena * demo: http://ishere.cn/demo/jquery.slidebox/ */ (function($){$.fn.slidebox=function(options){var defaults={direction:'left',duration:0.6,easing:'swing',delay:3,startindex:0,hideclickbar:true,clickbarradius:5,hidebottombar:false};var settings=$.extend(defaults,options||{});var wrapper=$(this),ul=wrapper.children('ul.items'),lis=ul.find('li'),firstpic=lis.first().find('img');var li_num=lis.size(),li_height=0,li_width=0;var init=function(){if(!wrapper.size())return false;wrapper.data('over',0);li_height=lis.first().height();li_width=lis.first().width();wrapper.css({width:li_width+'px',height:li_height+'px'});lis.css({width:li_width+'px',height:li_height+'px'});ul.append(ul.find('li:first').clone());li_num+=1;if(settings.direction=='left'){ul.css('width',li_num*li_width+'px')}else{ul.css('height',li_num*li_height+'px')}ul.find('li:eq('+settings.startindex+')').addclass('active');if(!settings.hidebottombar){var tips=$('
').css('opacity',0.6).appendto(wrapper);var title=$('').html(function(){var active=ul.find('li.active').find('a'),text=active.attr('title'),href=active.attr('href');return $('').attr('href',href).text(text)}).appendto(tips);var nums=$('').hide().appendto(tips);lis.each(function(i,n){var a=$(n).find('a'),text=a.attr('title'),href=a.attr('href'),css='';i==settings.startindex&&(css='active');$('').attr('href',href).text(text).addclass(css).css('borderradius',settings.clickbarradius+'px').mouseover(function(){wrapper.data('over',1);$(this).addclass('active').siblings().removeclass('active');ul.find('li:eq('+$(this).index()+')').addclass('active').siblings().removeclass('active');start()}).appendto(nums)});if(settings.hideclickbar){tips.hover(function(){nums.animate({top:'0px'},'fast')},function(){nums.animate({top:tips.height()+'px'},'fast')});nums.show().delay(2000).animate({top:tips.height()+'px'},'fast')}else{nums.show()}}lis.size()>1&&start()};var start=function(){var active=ul.find('li.active'),active_a=active.find('a');var index=active.index();if(settings.direction=='left'){offset=index*li_width*-1;param={'left':offset+'px'}}else{offset=index*li_height*-1;param={'top':offset+'px'}}wrapper.find('.nums').find('a:eq('+index+')').addclass('active').siblings().removeclass('active');wrapper.find('.title').find('a').attr('href',active_a.attr('href')).text(active_a.attr('title'));ul.stop().animate(param,settings.duration*1000,settings.easing,function(){active.removeclass('active');if(active.next().size()==0){ul.css({top:0,left:0}).find('li:eq(1)').addclass('active');wrapper.find('.nums').find('a:first').addclass('active').siblings().removeclass('active')}else{active.next().addclass('active')}wrapper.data('over')==0&&wrapper.data('timeid',window.settimeout(start,settings.delay*1000))})};var stop=function(){window.cleartimeout(wrapper.data('timeid'))};wrapper.hover(function(){wrapper.data('over',1);stop()},function(){wrapper.data('over',0);start()});var imgloader=new image();imgloader.onload=function(){imgloader.onload=null;init()};imgloader.src=firstpic.attr('src')}})(jquery);