Jquery implementation drop-down menu, jquery drop-down menu

Source: Internet
Author: User

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
  1. <Div class = "header_menu">
  2. <Ul>
  3. <Li class = "menuli" id = "xtgl_menu"> system management </li>
  4. <Li class = "menuli" id = "ggsq_menu"> Manager Office </li>
  5. <Li class = "menuli" id = "bhz_menu"> Protection Station </li>
  6. <Li class = "menuli" id = "mcjy_menu"> wood inspection </li>
  7. <Li class = "menuli" id = "slgh_menu"> forest management and protection </li>
  8. </Ul>
  9. </Div>
  10. <Div class = "display movediv" id = "slgh_menu_div">
  11. <Ul>
  12. <Li class = "redli"> attendance management </li>
  13. <Li class = "redli"> Inspection Management </li>
  14. <Li class = "redli"> onsite forensics </li>
  15. <Li class = "redli"> troubleshooting </li>
  16. </Ul>
  17. </Div>
  18. <Div class = "display movediv" id = "mcjy_menu_div">
  19. <Ul>
  20. <Li class = "redli"> location monitoring </li>
  21. <Li class = "redli"> Inspection Management </li>
  22. </Ul>
  23. </Div>
  24. <Div class = "display movediv" id = "bhz_menu_div">
  25. <Ul>
  26. <Li class = "redli"> attendance management </li>
  27. <Li class = "redli"> Regulatory Information </li>
  28. </Ul>
  29. </Div>
  30. <Div class = "display movediv" id = "ggsq_menu_div">
  31. <Ul>
  32. <Li class = "redli"> attendance management </li>
  33. <Li class = "redli"> Regulatory Information </li>
  34. </Ul>
  35. </Div>
  36. <Div class = "display movediv" id = "xtgl_menu_div">
  37. <Ul>
  38. <Li class = "redli"> permission management </li>
  39. <Li class = "redli"> device management </li>
  40. </Ul>
  41. </Div>

 

====================================== Css style:

Css code
  1. /** Header menu **/
  2. . Header_menu {
  3. Float: right;
  4. Width: 50%;
  5. Height: 100%;
  6. Cursor: pointer;
  7. }
  8. . Header_menu ul {
  9. List-style: none;
  10. Height: 100%;
  11. }
  12. . Header_menu ul li {
  13. Float: right;
  14. Width: 20%;
  15. Color: white;
  16. Font-size: 14px;
  17. Padding-top: 55px;
  18. Font-weight: bold;
  19. }
  20. . Display {
  21. Display: none;
  22. }
  23. . Display ul {
  24. List-style: none;
  25. Width: 100px;
  26. }
  27. . Display ul li {
  28. Padding-top: 10px;
  29. Padding-bottom: 5px;
  30. Padding-left: 5px;
  31. Cursor: pointer;
  32. Font-size: 14px;
  33. }
  34. . Movediv {
  35. Position: fixed;
  36. Left: 0px;
  37. Top: 0px;
  38. Font-size: 14px;
  39. White;
  40. Border: 1px solid white;
  41. }
  42. . Redcolor {
  43. # A0c9e6;
  44. }

 

===================================== Js scripts

Js Code
  1. $ (Function (){
  2. // Menu binding event
  3. InitMenuListener ();
  4. // Bind an event to the drop-down menu
  5. InitSubMenuHover ();
  6. // Change the color of the drop-down menu
  7. InitSubMenuLiHover ();
  8. });
  9. /**
  10. * Top menu binding slide events
  11. */
  12. Function initMenuListener (){
  13. $ (". Menuli"). hover (function (){
  14. Var hideDivId = $ (this). attr ("id") + "_ div ";
  15. // Obtain the menu position
  16. Var left = $ (this). offset (). left;
  17. Var top = $ (this). offset (). top;
  18. Var height = $ (this). outerHeight (); // outerHeight is to get the height, including the padding, height is to get the height, but only the text height
  19. $ ("#" + HideDivId). show ();
  20. $ ("#" + HideDivId).css ("left", left );
  21. $ ("#" + HideDivId).css ("top", top + height );
  22. }, Function (){
  23. // Hide the original menu
  24. $ (". Display"). hide ();
  25. });
  26. }
  27. /**
  28. * Events bound to the drop-down menu
  29. */
  30. Function initSubMenuHover (){
  31. $ (". Display"). hover (function (){
  32. $ (This). show ();
  33. }, Function (){
  34. $ (This). hide ();
  35. });
  36. }
  37. /**
  38. * Change the color from the drop-down menu.
  39. */
  40. Function initSubMenuLiHover (){
  41. $ (". Redli"). hover (function (){
  42. $ (This). addClass ("redcolor ");
  43. }, Function (){
  44. $ (This). removeClass ("redcolor ");
  45. });
  46. }

 

The effect is as follows:

Jquery implementation drop-down menu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.