Jquery implementation drop-down menu, jquery drop-down menu
Jquery is a lightweight framework that I personally think is very useful. Today I will write a very simple example to implement the drop-down menu function;
The jquery. js version must be referenced on the page;
Next, paste ================================ html:
Html code
- <Div class = "header_menu">
- <Ul>
- <Li class = "menuli" id = "xtgl_menu"> system management </li>
- <Li class = "menuli" id = "ggsq_menu"> Manager Office </li>
- <Li class = "menuli" id = "bhz_menu"> Protection Station </li>
- <Li class = "menuli" id = "mcjy_menu"> wood inspection </li>
- <Li class = "menuli" id = "slgh_menu"> forest management and protection </li>
- </Ul>
- </Div>
- <Div class = "display movediv" id = "slgh_menu_div">
- <Ul>
- <Li class = "redli"> attendance management </li>
- <Li class = "redli"> Inspection Management </li>
- <Li class = "redli"> onsite forensics </li>
- <Li class = "redli"> troubleshooting </li>
- </Ul>
- </Div>
- <Div class = "display movediv" id = "mcjy_menu_div">
- <Ul>
- <Li class = "redli"> location monitoring </li>
- <Li class = "redli"> Inspection Management </li>
- </Ul>
- </Div>
- <Div class = "display movediv" id = "bhz_menu_div">
- <Ul>
- <Li class = "redli"> attendance management </li>
- <Li class = "redli"> Regulatory Information </li>
- </Ul>
- </Div>
- <Div class = "display movediv" id = "ggsq_menu_div">
- <Ul>
- <Li class = "redli"> attendance management </li>
- <Li class = "redli"> Regulatory Information </li>
- </Ul>
- </Div>
- <Div class = "display movediv" id = "xtgl_menu_div">
- <Ul>
- <Li class = "redli"> permission management </li>
- <Li class = "redli"> device management </li>
- </Ul>
- </Div>
====================================== Css style:
Css code
- /** Header menu **/
- . Header_menu {
- Float: right;
- Width: 50%;
- Height: 100%;
- Cursor: pointer;
- }
- . Header_menu ul {
- List-style: none;
- Height: 100%;
- }
- . Header_menu ul li {
- Float: right;
- Width: 20%;
- Color: white;
- Font-size: 14px;
- Padding-top: 55px;
- Font-weight: bold;
- }
- . Display {
- Display: none;
- }
- . Display ul {
- List-style: none;
- Width: 100px;
- }
- . Display ul li {
- Padding-top: 10px;
- Padding-bottom: 5px;
- Padding-left: 5px;
- Cursor: pointer;
- Font-size: 14px;
- }
- . Movediv {
- Position: fixed;
- Left: 0px;
- Top: 0px;
- Font-size: 14px;
- White;
- Border: 1px solid white;
- }
- . Redcolor {
- # A0c9e6;
- }
===================================== Js scripts
Js Code
- $ (Function (){
- // Menu binding event
- InitMenuListener ();
- // Bind an event to the drop-down menu
- InitSubMenuHover ();
- // Change the color of the drop-down menu
- InitSubMenuLiHover ();
- });
- /**
- * Top menu binding slide events
- */
- Function initMenuListener (){
- $ (". Menuli"). hover (function (){
- Var hideDivId = $ (this). attr ("id") + "_ div ";
- // Obtain the menu position
- Var left = $ (this). offset (). left;
- Var top = $ (this). offset (). top;
- Var height = $ (this). outerHeight (); // outerHeight is to get the height, including the padding, height is to get the height, but only the text height
- $ ("#" + HideDivId). show ();
- $ ("#" + HideDivId).css ("left", left );
- $ ("#" + HideDivId).css ("top", top + height );
- }, Function (){
- // Hide the original menu
- $ (". Display"). hide ();
- });
- }
- /**
- * Events bound to the drop-down menu
- */
- Function initSubMenuHover (){
- $ (". Display"). hover (function (){
- $ (This). show ();
- }, Function (){
- $ (This). hide ();
- });
- }
- /**
- * Change the color from the drop-down menu.
- */
- Function initSubMenuLiHover (){
- $ (". Redli"). hover (function (){
- $ (This). addClass ("redcolor ");
- }, Function (){
- $ (This). removeClass ("redcolor ");
- });
- }
The effect is as follows:
Jquery implementation drop-down menu