Reload

Remember

导航

可隐藏导航栏

Posted on 2004-07-22 09:23  Handi.Z  阅读(3639)  评论(0)    收藏  举报

Javascript

//==================
//
Handi @ 2004.7.5
//
Handi.Z@126.com
//
==================
//
//
创建左边导航栏
//
所有Begin开头的函数,都必须有End开头的同名函数结束
//
e.g.
//
//
BeginCreateNavigator('#87cefa');
//
//
BeginCreateMainItem('客户查询','main1','Images/Folder.gif','blue','#87cefa');
//
CreateSubItem('子查询1','search1.aspx','Images/Folder.gif','blue','#87cefa');
//
CreateSubItem('子查询2','search2.aspx','Images/Folder.gif','blue','#87cefa');
//
EndCreateMainItem();
//
//
CreateHyperlink('雅虎网站','http://www.yahoo.com','Images/Folder.gif','blue','#87cefa');
//
//
BeginCreateMainItem('古镇风光','main2','Images/Folder.gif','blue','#87cefa');
//
CreateSubItem('古香古色','old1.aspx','Images/Folder.gif','blue','#87cefa');
//
CreateSubItem('古色古香','old2.aspx','Images/Folder.gif','blue','#87cefa');
//
EndCreateMainItem();
//
//
BeginCreateMainItem('客户留言','main3','Images/Folder.gif','blue','#87cefa');
//
CreateSubItem('论坛','old1.aspx','Images/Folder.gif','blue','#87cefa');
//
CreateSubItem('FAQ','old2.aspx','Images/Folder.gif','blue','#87cefa');
//
EndCreateMainItem();
//
//
EndCreateNavigator('yellow');


var MSIE=0;
if(navigator.appName=='Microsoft Internet Explorer') MSIE=1;
var lastitemid='undefined';//最后的一个菜单
var leftbannerwidth='120';//导航栏宽度
var mainitemfolder='Images/Folder.BMP';//主菜单title前面的图片地址
var subitemfolder='Images/GoNow.bmp';//子菜单(包括不可展开的主菜单)title前面的图片地址
var tableback='#336699';//导航栏背景色
var toolback='blue';//显示/隐藏导航栏工具条 背景色
var Overcolor='blue';//鼠标悬于菜单上时菜单的背景色
var Outcolor='#336699';//鼠标离开菜单后菜单的背景色

//创建整个导航栏的框架,backcolor为导航栏的背景色
function BeginCreateNavigator(backcolor)
{
    document.write(
"<table cellpadding=0 cellspacing=0 bgcolor=" + backcolor + " align=left height=100%    border=0><tr><td valign=top>");
    document.write(
"<table width=" + leftbannerwidth + " id="LeftBanner" cellpadding=0 cellspacing=0 height=100%><script>LeftBanner.style.display='block';</script>");
}

function BeginCreateNavigatorI()
{
    BeginCreateNavigator(tableback);
}

//导航栏的结束标记,backcolor为 显示/隐藏导航栏工具条 的背景色
function EndCreateNavigator(backcolor)
{
    document.write(
"<tr id="LastTR" height=100%><td></td></tr></table></td><td width="10" bgcolor="+backcolor+" style="CURSOR: hand" onclick="SwitchLeft()">");
    document.write(
"<img id="GoOrBackPic" src="Images/BackArrow.gif" border=0 alt="隐藏导航栏"></td></tr></table>");
}

function EndCreateNavigatorI()
{
    EndCreateNavigator(toolback)
}

//创建可展开菜单的主菜单
//
title : 显示的字
//
id : 菜单的id,如果有多个主菜单,不可有相同的id
//
folderid : 主菜单title前面的图片地址
//
overcolor : 鼠标悬于菜单上时菜单的背景色
//
outcolor : 鼠标离开菜单后菜单的背景色
function BeginCreateMainItem(title,id,pic,overcolor,outcolor)
{
    document.write(
"<tr valign=top><td onclick=SlipMenu('" + id + "') onmouseover=MouseOver(this,'" + overcolor + "') onmouseout=MouseOut(this,'" + outcolor + "') class=leftTD><img src='" + pic + "' border=0 align="absmiddle">" + title + "</td></tr>");
    document.write(
"<tr><td id="" + id + "" style="visibility:hidden;height:0px;" valign=top><script>if(MSIE)" + id + ".style.display='none';</script>");
}

function BeginCreateMainItemI(title,id)
{
    BeginCreateMainItem(title,id,mainitemfolder,Overcolor,Outcolor);
}

//可展开菜单的主菜单的结束标记
function EndCreateMainItem()
{
    document.write(
"</td></tr>");
}

function EndCreateMainItemI()
{
    EndCreateMainItem();
}

//创建可展开菜单的子菜单
//
title : 显示的字
//
link : 链接,点击菜单后的目标链接
//
overcolor : 鼠标悬于菜单上是菜单的背景色
//
outcolor : 鼠标离开菜单后菜单的背景色
function CreateSubItem(title,link,pic,overcolor,outcolor)
{
    document.write(
"<div onclick="javascript:window.open('" + link + "','_self');" onmouseover=MouseOver(this,'" + overcolor + "') onmouseout=MouseOut(this,'" + outcolor + "') class=leftDIV><img src='" + pic + "' border=0 align="absmiddle">" + title + "</div>");
}

function CreateSubItemI(title,link)
{
    CreateSubItem(title,link,subitemfolder,Overcolor,Outcolor);
}

//创建不可展开的主菜单
//
title : 显示的字
//
link : 链接,点击菜单后的目标链接
//
overcolor : 鼠标悬于菜单上是菜单的背景色
//
outcolor : 鼠标离开菜单后菜单的背景色
function CreateHyperlink(title,link,pic,overcolor,outcolor)
{
    document.write(
"<tr valign=top><td onclick="javascript:window.open('" + link + "','_self');" onmouseover=MouseOver(this,'" + overcolor + "') onmouseout=MouseOut(this,'" + outcolor + "') class=leftTD><img src=' " + pic + "' border=0 align="absmiddle">" + title + "</td></tr>");
}

function CreateHyperlinkI(title,link)
{
    CreateHyperlink(title,link,subitemfolder,Overcolor,Outcolor);
}

//滑动主菜单
//
itemid : 子菜单的id
function SlipMenu(itemid)
{
    
if(itemid=='none')
    
return;
    
    
var item=document.getElementById(itemid);    
    
var enditem=document.getElementById('LastTR');
    
    
if(item==null || enditem==null)
    
return;
    
    item
=item.style;
    enditem
=enditem.style;
    
    
if(lastitemid!='undefined')
    {
        
var lastitem=document.getElementById(lastitemid).style;
        
if(MSIE)lastitem.display='none';
        
else
        {
            lastitem.visibility
='hidden';
            lastitem.height
='0';
        }
    }
    
if(itemid==lastitemid)
    {
        
if(MSIE)enditem.display='block';
        enditem.visibility
='visible';
        enditem.height
='100%';
        lastitemid
='undefined';
    }
    
else
    {
        
if(MSIE)
        {
            enditem.display
='none';
            item.display
='block';
        }
        enditem.visibility
='hidden';
        enditem.height
='0';
        item.height
='100%';
        item.visibility
='visible';
        lastitemid
=itemid;
    }
}

//隐藏或显示导航栏
function SwitchLeft()
{    
    
if(LeftBanner.style.display=='block')
    {
        LeftBanner.style.display
='none';
        GoOrBackPic.src
='Images/GoArrow.gif';
        GoOrBackPic.alt
='显示导航栏';
    }
    
else
    {
        LeftBanner.style.display
='block';
        GoOrBackPic.src
='Images/BackArrow.gif';
        GoOrBackPic.alt
='隐藏导航栏';
    }
}

function MouseOver(item,color)
{
    item.style.backgroundColor
=color;
}

function MouseOut(item,color)
{
    item.style.backgroundColor
=color;
}