置于head中:
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
<style type="text/css">
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//* DEMO CSS */
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
a
{
color:red;
text-decoration:none;
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
body
{
font-size:0.8em;
text-align:center;
background-color:#E2EBED;
font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif;
margin:0px;
padding:0px;
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
img
{
border:0px;
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
#mainContainer
{
width:760px;
margin:0 auto;
text-align:left;
background-color:#FFF;
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
#leftContainer
{
width:160px;
float:left;
padding-left:5px;
padding-right:5px;
height:300px;
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
#contentContainer
{
width:590px;
float:left;
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
.ad
{
clear:both;
text-align:center;
padding:5px;
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//* END DEMO CSS */
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
#dhtmlgoodies_menu
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
font-family:arial; /**//* Font for main menu items */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
width:150px; /**//* Width of main menu */
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
#dhtmlgoodies_menu li
{ /**//* Main menu <li> */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
list-style-type:none; /**//* No bullets */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
margin:0px; /**//* No margin - needed for Opera */
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
#dhtmlgoodies_menu ul
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
margin:0px; /**//* No <ul> air */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
padding:0px; /**//* No <ul> air */
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
#dhtmlgoodies_menu ul li ul
{ /**//* Styling for those who doesn't have javascript enabled */
padding-left:10px;
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
#dhtmlgoodies_menu li a
{ /**//* Main menu links */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
text-decoration:none; /**//* No underline */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
color:#000; /**//* Black text color */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
height:20px; /**//* 20 pixel height */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
line-height:20px; /**//* 20 pixel height */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
vertical-align:middle; /**//* Align text in the middle */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
border:1px solid #000; /**//* Black border */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
background-color:#FAFAFA; /**//* Light blue background color */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
margin:1px; /**//* A little bit of air */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
padding:1px; /**//* Air between border and text inside */
display:block;
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
#dhtmlgoodies_menu li a:hover,#dhtmlgoodies_menu .activeMainMenuItem
{
color:#FFF;
background-color:#317082;
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
.dhtmlgoodies_subMenu
{
visibility:hidden;
position:absolute;
overflow:hidden;
border:1px solid #000;
background-color:#FAFAFA;
font-family:arial;
text-align:left;
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
.dhtmlgoodies_subMenu ul
{
margin:0px;
padding:0px;
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
.dhtmlgoodies_subMenu ul li
{
list-style-type:none;
margin:0px;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
padding:1px; /**//* 1px of air between submenu border and sub menu item - (the "white" space you see on mouse over )*/
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
.dhtmlgoodies_subMenu ul li a
{ /**//* Sub menu items */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
white-space:nowrap; /**//* No line break */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
text-decoration:none; /**//* No underline */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
color:#000; /**//* Black text color */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
height:16px; /**//* 16 pixels height */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
line-height:16px; /**//* 16 pixels height */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
padding:1px; /**//* 1px of "air" inside */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
display:block; /**//* Display as block - you shouldn't change this */
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
.dhtmlgoodies_subMenu ul li a:hover
{ /**//* Sub menu items - mouse over effects */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
color:#FFF; /**//* White text */
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
background-color:#317082; /**//* Blue background */
}
![](/Images/OutliningIndicators/None.gif)
</style>
<script type="text/javascript">
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//************************************************************************************************************
(C) www.dhtmlgoodies.com, November 2005
This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.
Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.
Thank you!
www.dhtmlgoodies.com
Alf Magne Kalleland
************************************************************************************************************/
![](/Images/OutliningIndicators/None.gif)
var timeBeforeAutoHide = 700; // Microseconds to wait before auto hiding menu(1000 = 1 second)
var slideSpeed_out = 10; // Steps to move sub menu at a time ( higher = faster)
var slideSpeed_in = 10;
var slideTimeout_out = 25; // Microseconds between slide steps ( lower = faster)
var slideTimeout_in = 10; // Microseconds between slide steps ( lower = faster)
var showSubOnMouseOver = true; // false = show sub menu on click, true = show sub menu on mouse over
var fixedSubMenuWidth = false; // Width of sub menu items - A number(width in pixels) or false when width should be dynamic
var xOffsetSubMenu = 0; // Offset x-position of sub menu items - use negative value if you want the sub menu to overlap main menu
var slideDirection = 'right'; // Slide to left or right ?
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//* Don't change anything below here */
var activeSubMenuId = false;
var activeMainMenuItem = false;
var currentZIndex = 1000;
var autoHideTimer = 0;
var submenuObjArray = new Array();
var okToSlideInSub = new Array();
var subPositioned = new Array();
![](/Images/OutliningIndicators/None.gif)
function stopAutoHide()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
autoHideTimer = -1;
}
function initAutoHide()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
autoHideTimer = 0;
if(autoHideTimer>=0)autoHide();
}
function autoHide()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
if(autoHideTimer>timeBeforeAutoHide)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(activeMainMenuItem)
{
activeMainMenuItem.className='';
activeMainMenuItem = false;
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(activeSubMenuId)
{
var obj = document.getElementById('subMenuDiv' + activeSubMenuId);
showSub();
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
}else
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(autoHideTimer>=0)
{
autoHideTimer+=50;
setTimeout('autoHide()',50);
}
}
}
function getTopPos(inputObj)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
var returnValue = inputObj.offsetTop;
while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
return returnValue;
}
function getLeftPos(inputObj)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
var returnValue = inputObj.offsetLeft;
while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
return returnValue;
}
function showSub()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
var subObj = false;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(this && this.tagName)
{
var numericId = this.parentNode.id.replace(/[^0-9]/g,'');
okToSlideInSub[numericId] = false;
var subObj = document.getElementById('subMenuDiv' + numericId);
if(activeMainMenuItem)activeMainMenuItem.className='';
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(subObj)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(!subPositioned[numericId])
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(slideDirection=='right')
{
subObj.style.left = getLeftPos(submenuObjArray[numericId]['parentDiv']) + submenuObjArray[numericId]['parentDiv'].offsetWidth + xOffsetSubMenu + 'px';
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
}else
{
subObj.style.left = getLeftPos(submenuObjArray[numericId]['parentDiv']) + xOffsetSubMenu + 'px';
}
submenuObjArray[numericId]['left'] = subObj.style.left.replace(/[^0-9]/g,'');
subObj.style.top = getTopPos(submenuObjArray[numericId]['parentDiv']) + 'px';
subPositioned[numericId] = true;
}
subObj.style.visibility = 'visible';
subObj.style.zIndex = currentZIndex;
currentZIndex++;
this.className='activeMainMenuItem';
activeMainMenuItem = this;
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
}else
{
var numericId = activeSubMenuId;
}
if(activeSubMenuId && (numericId!=activeSubMenuId || !subObj))slideMenu(activeSubMenuId,(slideSpeed_in*-1));
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(numericId!=activeSubMenuId && this && subObj)
{
subObj.style.width = '0px';
slideMenu(numericId,slideSpeed_out);
activeSubMenuId = numericId;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
}else
{
if(numericId!=activeSubMenuId)activeSubMenuId = false;
}
if(showSubOnMouseOver)stopAutoHide();
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
function slideMenu(menuIndex,speed)
{
var obj = submenuObjArray[menuIndex]['divObj'];
var obj2 = submenuObjArray[menuIndex]['ulObj'];
var width = obj.offsetWidth + speed;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(speed<0)
{
if(width<0)width = 0;
obj.style.width = width + 'px';
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(slideDirection=='left')
{
obj.style.left = submenuObjArray[menuIndex]['left'] - width + 'px';
obj2.style.left = '0px';
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
}else
{
obj2.style.left = width - submenuObjArray[menuIndex]['width'] + 'px'
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(width>0 && okToSlideInSub[menuIndex])setTimeout('slideMenu(' + menuIndex + ',' + speed + ')',slideTimeout_in); else
{
obj.style.visibility = 'hidden';
obj.style.width = '0px';
if(activeSubMenuId==menuIndex)activeSubMenuId=false;
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
}else
{
if(width>submenuObjArray[menuIndex]['width'])width = submenuObjArray[menuIndex]['width'];
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(slideDirection=='left')
{
obj.style.left = submenuObjArray[menuIndex]['left'] - width + 'px';
obj2.style.left = '0px';
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
}else
{
obj2.style.left = width - submenuObjArray[menuIndex]['width'] + 'px'
}
obj.style.width = width + 'px';
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(width<submenuObjArray[menuIndex]['width'])
{
setTimeout('slideMenu(' + menuIndex + ',' + speed + ')',slideTimeout_out);
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
}else
{
okToSlideInSub[menuIndex] = true;
}
}
}
function resetPosition()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
subPositioned.length = 0;
}
function initLeftMenu()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
var menuObj = document.getElementById('dhtmlgoodies_menu');
var mainMenuItemArray = new Array();
var mainMenuItem = menuObj.getElementsByTagName('LI')[0];
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
while(mainMenuItem)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(mainMenuItem.tagName && mainMenuItem.tagName.toLowerCase()=='li')
{
mainMenuItemArray[mainMenuItemArray.length] = mainMenuItem;
var aTag = mainMenuItem.getElementsByTagName('A')[0];
if(showSubOnMouseOver)
aTag.onmouseover = showSub;
else
aTag.onclick = showSub;
}
mainMenuItem = mainMenuItem.nextSibling;
}
var lis = menuObj.getElementsByTagName('A');
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(var no=0;no<lis.length;no++)
{
if(!showSubOnMouseOver)lis[no].onmouseover = stopAutoHide;
lis[no].onmouseout = initAutoHide;
lis[no].onmousemove = stopAutoHide;
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(var no=0;no<mainMenuItemArray.length;no++)
{
var sub = mainMenuItemArray[no].getElementsByTagName('UL')[0];
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(sub)
{
mainMenuItemArray[no].id = 'mainMenuItem' + (no+1);
var div = document.createElement('DIV');
div.className='dhtmlgoodies_subMenu';
document.body.appendChild(div);
div.appendChild(sub);
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(slideDirection=='right')
{
div.style.left = getLeftPos(mainMenuItemArray[no]) + mainMenuItemArray[no].offsetWidth + xOffsetSubMenu + 'px';
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
}else
{
div.style.left = getLeftPos(mainMenuItemArray[no]) + xOffsetSubMenu + 'px';
}
div.style.top = getTopPos(mainMenuItemArray[no]) + 'px';
div.id = 'subMenuDiv' + (no+1);
sub.id = 'submenuUl' + (no+1);
sub.style.position = 'relative';
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(navigator.userAgent.indexOf('Opera')>=0)
{
submenuObjArray[no+1] = new Array();
submenuObjArray[no+1]['parentDiv'] = mainMenuItemArray[no];
submenuObjArray[no+1]['divObj'] = div;
submenuObjArray[no+1]['ulObj'] = sub;
submenuObjArray[no+1]['width'] = sub.offsetWidth;
submenuObjArray[no+1]['left'] = div.style.left.replace(/[^0-9]/g,'');
}
sub.style.left = 1 - sub.offsetWidth + 'px';
if(document.all)div.style.width = '1px';
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(navigator.userAgent.indexOf('Opera')<0)
{
submenuObjArray[no+1] = new Array();
submenuObjArray[no+1]['parentDiv'] = mainMenuItemArray[no];
submenuObjArray[no+1]['divObj'] = div;
submenuObjArray[no+1]['ulObj'] = sub;
submenuObjArray[no+1]['width'] = sub.offsetWidth;
submenuObjArray[no+1]['left'] = div.style.left.replace(/[^0-9]/g,'');
if(fixedSubMenuWidth)submenuObjArray[no+1]['width'] = fixedSubMenuWidth;
}
![](/Images/OutliningIndicators/InBlock.gif)
if(!document.all)div.style.width = '1px';
}
}
![](/Images/OutliningIndicators/InBlock.gif)
menuObj.style.visibility = 'visible';
window.onresize = resetPosition;
}
window.onload = initLeftMenu;
</script>
![](/Images/OutliningIndicators/None.gif)
置于body内:
<div id="mainContainer">
<div id="topBar">
<a href="http://dhtmlgoodies.com"><img src="http://www.dhtmlgoodies.com/images/heading3.gif"></a>
</div>
<div id="leftContainer">
<!--- START MENU HTML -->
<div id="dhtmlgoodies_menu">
<ul>
<li><a href="#">New scripts</a>
<ul>
<li><a href="#">Slide out menu</a></li>
<li><a href="#">Content organizer</a></li>
<li><a href="#">Slide in pane</a></li>
<li><a href="#">Chess widget</a></li>
<li><a href="#">Color picker</a></li>
</ul>
</li>
<li><a href="#">Updated scripts</a>
<ul>
<li><a href="#">Calendar script</a></li>
<li><a href="#">Tab menu</a></li>
<li><a href="#">DHTML menu</a></li>
<li><a href="#">Slide in pane</a></li>
</ul>
</li>
<li><a href="#">Support us</a>
<ul>
<li><a href="#">Link to us</a></li>
<li><a href="#">Recommend us</a></li>
<li><a href="#">Donate</a></li>
</ul>
</li>
<li><a href="#">Forum</a>
<ul>
<li><a href="#">Topic one</a></li>
<li><a href="#">Topic two</a></li>
<li><a href="#">Topic three</a></li>
</ul>
</li>
<li><a href="#">Contact us</a>
<ul>
<li><a href="#">Support</a></li>
<li><a href="#">Feedback</a></li>
<li><a href="#">Submit a script</a></li>
</ul>
</li>
<li><a href="#">The end(no subs)</a></li>
</ul>
</div>
<!-- END MENU HTML-->
</div>
<div id="contentContainer">
This is a menu based on an unordered list. You use HTML to build your menu. That makes the menu friendly to search engines.
</div>
</div>
![](/Images/OutliningIndicators/None.gif)
配置以下:
var timeBeforeAutoHide = 700;
var slideSpeed_out = 10;
var slideSpeed_in = 10;
var slideTimeout_out = 25;
var slideTimeout_in = 10;
var showSubOnMouseOver = true;
var fixedSubMenuWidth = false;
var xOffsetSubMenu = 0;
var slideDirection = 'right'; var firefox15SubWidth = 110;
- timeBeforeAutoHide = Delay in microseconds from when mouse leaves menu until it's hidden automatically
- slideSpeed_out = Slide speed out - higher value = faster
- slideSpeed_in = Slide speed in - higher value = faster
- slideTimeout_out = Slide speed out - microseconds between each step(Lower = faster)
- slideTimeout_in = Slide speed in - microseconds between each step(Lower = faster)
- showSubOnMouseOver = Show sub menu on mouse over or mouse click. true = mouse over, false = mouse click.
- fixedSubMenuWidth = Sub menu width in pixel. Use false if width should be set automatically.
- xOffsetSubMenu = pixel to offset sub menu(horizontally). (You might want to use -2 if the menu slides to the left)
- slideDirection = Slide menu to the left or to the right.
![](/images/cnblogs_com/komazhang/menu_1.GIF)