This article illustrates the extension-shrink menu code implemented by JavaScript. Share to everyone for your reference. Specifically as follows:
The screenshot of the running effect is as follows:
Mouse hover when the menu item up to the blue background white, click on the bottom will have a blue bar to indicate the current selection.
Page code, each item of the menu is a div, including a UL used to place display text and so on, another div is the bottom of the blue bar, you need to give the first and last set different class, style needs to use:
<div id= "NAV" > <div class= "Navitem indexnavitem" > <ul class= "navUl" > <li> Home </li> <li class= "Hoverli" > Home </li> </ul> <div class= "Highlighter s Electednav "></div> </div> <div class=" Navitem "> <ul class=" Navul "> <li>a< ;/li> <li class= "Hoverli" >A</li> </ul> <div class= "highlighter" ></div> < /div> <div class= "Navitem lastnavitem" > <ul class= "Navul" > <li>A</li> <li class= "Hoverli" >A</li> </ul> <div class= "highlighter" ></div> </div> <div I
D= "Logoutnavitem" class= "Navitem logoutnavitem lastnavitem" > <ul class= "Navul" > <li> exit </li> <li class= "Hoverli" > Exit </li> </ul> <div class= "highlighter" ></div> </div > </div>
The
style, which is mainly the setting of the left and right borders of each menu item, and the UL and Li position settings:
* {padding:0;
margin:0;
Body {background-color: #fffff3;
Font:12px/1.6em Helvetica, Arial, Sans-serif;
} ul,li{List-style:none} #nav {text-align:center;
height:50px;
font-size:10px;
line-height:30px;
Background-color: #F0E6DB;
margin-bottom:10px;
}. navitem {cursor:pointer;
position:relative;
Float:left;
width:100px;
height:50px;
font-size:15px;
BORDER-RIGHT:2PX solid RGB (255,255,255);
BORDER-LEFT:2PX solid RGB (255,255,255);
Overflow:hidden;
Font-weight:bold;
}. Indexnavitem {border-left:4px solid rgb (255,255,255);
margin-left:10px;
}. Lastnavitem {border-right:4px solid rgb (255,255,255);}. logoutnavitem {float:right;
width:120px;
margin-right:10px;
BORDER-LEFT:4PX solid RGB (255,255,255);
}. navul {position:relative;
height:100px;
width:100%;
border-bottom:5px solid RGB (2,159,212);
}. Navul Li {height:50px;
line-height:50px;
}. highlighter {position:absolute;
bottom:0;
height:5px;
width:100%; }. SElectednav {background-color: #029FD4;} hoverli {background-color: #029FD4;
Color: #ffffff;
}
Next is to the menu to write a suspension and click the event JS code, the suspension will be the UL on the height of the Li, the mouse to move away and then restore, after the click is to the Blue bar div add style can be:
$ (function () {
$ (". Navitem"). Hover (function () {
$ (this). Children ("ul"). Animate ({top
: " -50px"
},
function () {
$ (this). Children ("ul"). Animate ({top
: 0px
}, mb
); $ (". Navitem"). Click (Function (event) {
$ (this). Siblings (). Children ('. Highlighter '). Removeclass (' Selectednav ');
$ (this). Children ('. Highlighter '). addclass (' Selectednav ');
});
}
The above is jquery to achieve a concise navigation menu effect of the key code, I hope to help you learn.