/* ================================================= // jquery tabs plugins 1.0 // author:chenyg@5173.com // url:http://stylechen.com/jquery-tabs.html // 4th dec 2010 // =================================================*/ ;(function($){ $.fn.extend({ tabs:function(options){ // 处理参数 options = $.extend({ event : 'mouseover', timeout : 0, auto : 0, callback : null }, options); var self = $(this), tabbox = self.children( 'div.tab_box' ).children( 'div' ), menu = self.children( 'ul.tab_menu' ), items = menu.find( 'li' ), timer; var tabhandle = function( elem ){ elem.siblings( 'li' ) .removeclass( 'current' ) .end() .addclass( 'current' ); tabbox.siblings( 'div' ) .addclass( 'hide' ) .end() .eq( elem.index() ) .removeclass( 'hide' ); }, delay = function( elem, time ){ time ? settimeout(function(){ tabhandle( elem ); }, time) : tabhandle( elem ); }, start = function(){ if( !options.auto ) return; timer = setinterval( autorun, options.auto ); }, autorun = function(){ var current = menu.find( 'li.current' ), firstitem = items.eq(0), len = items.length, index = current.index() + 1, item = index === len ? firstitem : current.next( 'li' ), i = index === len ? 0 : index; current.removeclass( 'current' ); item.addclass( 'current' ); tabbox.siblings( 'div' ) .addclass( 'hide' ) .end() .eq(i) .removeclass( 'hide' ); }; items.bind( options.event, function(){ delay( $(this), options.timeout ); if( options.callback ){ options.callback( self ); } }); if( options.auto ){ start(); self.hover(function(){ clearinterval( timer ); timer = undefined; },function(){ start(); }); } return this; } }); })(jquery);