小虫快跑

.net爱好者

  博客园 :: 首页 :: 联系 :: 订阅 订阅 :: 管理
  20 Posts :: 15 Stories :: 24 Comments :: 1 Trackbacks

公告

    YL_MenuBar={
        menuid:"",
        menus:null,
        menusLength:0,
        menuSmalls:null,
        defaultIndex:0,
        defaultIndexSmall:0,
        curcss:"cur",
        nobr:"nobr",
        $:function(menuid)
        {
            return document.getElementById(menuid);
        },
        setMenu:function(menuid,curindex,bigrq,smallrq,curcss,nobrcss)
        {
            var tempObj,tcurb,tcurs;
            tcurb=0;
            tcurs=0;
            //拆分处理当前链接索引
            if (curindex.toString().indexOf(".")>-1) //当存在“.”时表示有子分类选定
            {
                var curAry=    curindex.split(".");
                tcurb=parseInt(curAry[0]);
                if (curAry.length>1 && curAry[1]!="")
                {
                    tcurs=parseInt(curAry[1]);
                }
                
            }else
            {
                tcurb=parseInt(curindex);
            }
            
            this.defaultIndex=tcurb;
            this.defaultIndexSmall=tcurs;
            this.curcss=curcss?curcss:this.curcss;
            this.nobr=nobrcss?nobrcss:this.nobr;
            this.menus=this.$(menuid).getElementsByTagName(bigrq);
            this.menusLength=this.menus.length;
            this.menuSmalls=new Array();
            for(i=0;i
<this.menusLength;i++)
            {
                tempObj
=this.menus[i].getElementsByTagName("ul")[0];
                
if (tempObj)
                {
                    tempObj.style.display
="none";
                }
                //if (tempObj!
="undefined")
                //{
                //    tempObj.thisIndex
=i;
                
//    tempObj.onmouseover=function(){YL_MenuBar.overMenu(this.thisIndex)};
                
//    tempObj.onmouseout=function(){YL_MenuBar.outMenu()};
                
//}
                this.menuSmalls[i]
=!tempObj?null:tempObj;
                
//加入事件,和索引属性
                this.menus[i].thisIndex
=i+1;
                
this.menus[i].onmouseover=function(){YL_MenuBar.overMenu(this.thisIndex)};
                
this.menus[i].onmouseout=function(){YL_MenuBar.outMenu()};
            
}
            this.overMenu(this.defaultIndex);
            if (this.defaultIndex
>0 && this.menus[this.defaultIndex-1])
            {
                var curliObjs = this.menus[this.defaultIndex-1].getElementsByTagName("li");
                
                if (curliObjs && curliObjs.length>=this.defaultIndexSmall && this.defaultIndexSmall>0)
                {
                    curliObjs[this.defaultIndexSmall-1].className="cur";
                }
            }
        },
        overMenu:function(index)
        {
            for(i=0;i
<this.menusLength;i++)
            {
                if (this.menuSmalls[i])
                {
                    this.menuSmalls[i].style.display
="none";
                }
            this.menus[i].className
="";
            }
            index--;
            if (index
>-1)
            {
                this.menus[index].className=this.curcss;
                if (this.menuSmalls[index])
                {
                    this.menuSmalls[index].style.display="block";
                }
                if (index
<this.menusLength-1)
                {
                    this.menus[index+1].className
=this.nobr;
                
}
                if (index!
=0)
                
{
                    this.menus[0].className
=this.nobr;
                
}
            }
        },
        outMenu:function()
        {
            this.overMenu(this.defaultIndex);
        }
    }
posted on 2009-05-07 10:55 最坏是单飞 阅读(61) 评论(0)  编辑 收藏