/* 滑动菜单 * 作者:gavin * 创建时间:2009-02-26 * 最后一次修改时间:2009-03-03 */ var ddsmoothmenu={ //菜单参数设置 //specify full url to down and right arrow images (23 is padding-right added to top level lis with drop downs): arrowimages: {down:['downarrowclass', './images/down.gif', 0], right:['rightarrowclass', './images/right.gif']}, //用时: transition: {overtime:300, outtime:300}, ///////stop configuring beyond here/////////////////////////// detectwebkit: navigator.useragent.tolowercase().indexof("applewebkit")!=-1, //detect webkit browsers (safari, chrome etc) getajaxmenu:function($, setting){ //function to fetch external page containing the panel divs var $menucontainer=$('#'+setting.contentsource[0]) //reference empty div on page that will hold menu $menucontainer.html("loading menu...") $.ajax({ url: setting.contentsource[1], //path to external menu file async: true, error:function(ajaxrequest){ $menucontainer.html('error fetching content. server response: '+ajaxrequest.responsetext) }, success:function(content){ $menucontainer.html(content) ddsmoothmenu.buildmenu($, setting) } }) }, buildmenu:function($, setting){ var smoothmenu=ddsmoothmenu var $mainmenu=$("#"+setting.mainmenuid+">ul") //reference main menu ul var $headers=$mainmenu.find("ul").parent() $mainmenu.filter(":empty").remove() $headers.each(function(i){ var $curobj=$(this).css({zindex: 100-i}) //reference current li header var $subul=$(this).find('ul:eq(0)').css({display:'block'}) this._dimensions={w:this.offsetwidth, h:this.offsetheight, subulw:$subul.outerwidth(), subulh:$subul.outerheight()} this.istopheader=$curobj.parents("ul").length==1? true : false //is top level header? $subul.css({top:this.istopheader? this._dimensions.h+"px" : 0}) /************* begin adding arrow **********/ /*$curobj.children("a:eq(0)").css(this.istopheader? {paddingright: smoothmenu.arrowimages.down[2]} : {}).append( '' )*/ /************* end adding arrow **********/ $curobj.hover( function(e){ var $targetul=$(this).children("ul:eq(0)") this._offsets={left:$(this).offset().left, top:$(this).offset().top} var menuleft=this.istopheader? 0 : this._dimensions.w menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft //calculate this sub menu's offsets from its parent if ($targetul.queue().length<=1){ //if 1 or less queued animations $targetul.css({left:menuleft+"px", width:this._dimensions.subulw+'px'}).animate({height:'show',opacity:'show'}, ddsmoothmenu.transition.overtime) } $(this).children("a").addclass("active") }, function(e){ var $targetul=$(this).children("ul:eq(0)") $targetul.animate({height:'hide', opacity:'hide'}, ddsmoothmenu.transition.outtime) $(this).children("a").removeclass("active") } ) //end hover }) //end $headers.each() $mainmenu.find("ul").css({display:'none', visibility:'visible'}) }, init:function(setting){ if (typeof setting.customtheme=="object" && setting.customtheme.length==2){ var mainmenuid='#'+setting.mainmenuid document.write('') } jquery(document).ready(function($){ //override default menu colors (default/hover) with custom set? //alert(setting.mainmenuid); $("#"+setting.mainmenuid+" ul").not(":has('li')").remove() if (typeof setting.contentsource=="object"){ //if external ajax menu ddsmoothmenu.getajaxmenu($, setting) } else{ //else if markup menu ddsmoothmenu.buildmenu($, setting) } }) } } //end ddsmoothmenu variable //初始化菜单: ddsmoothmenu.init({ mainmenuid: "mainnav", //菜单 div id contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"] })