(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); //范例 //
元素 .siblings().hide(); //隐藏其它几个同辈的
元素 }) $(".nav").mouseleave(function() { var $this = $(this); var thisa = $this.find(".active"); var inde = thisa.index(); //alert(inde) $this.find(".navInithems").removeClass("current"); thisa.addClass("current"); $this.find(".tab_box").children("div").addClass("hide"); $this.find(".tab_box").children("div").eq(inde).removeClass("hide"); }); //文本域显示隐藏 $(".xz_cx_input").focus(function(){ if($(this).val() ==this.defaultValue){ $(this).val(""); } }).blur(function(){ if ($(this).val() == '') { $(this).val(this.defaultValue); } }); // 表格换色 $(".cx_tab tbody tr:odd").addClass("odd"); $(".cx_tab tbody tr:even").addClass("even"); }); (function($){ $.fn.extend({ Scroll:function(opt,callback){ //参数初始化 if(!opt) var opt={}; var _this=this.eq(0).find("div:first"); var lineH=_this.find("ul:first").height(), //获取行高 line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), //每次滚动的行数,默认为一屏,即父容器高度 speed=opt.speed?parseInt(opt.speed,10):500, //卷动速度,数值越大,速度越慢(毫秒) timer=opt.timer?parseInt(opt.timer,10):3000; //滚动的时间间隔(毫秒) if(line==0) line=1; var upHeight=0-line*lineH; //滚动函数 scrollUp=function(){ _this.animate({ marginTop:upHeight },speed,function(){ for(i=1;i<=line;i++){ _this.find("ul:first").appendTo(_this); } _this.css({marginTop:0}); }); } //鼠标事件绑定 _this.hover(function(){ clearInterval(timerID); },function(){ timerID=setInterval("scrollUp()",timer); }).mouseout(); } }) })(jQuery); $(document).ready(function(){ $("#ooxx").Scroll({line:3,speed:500,timer:3000}); });