jquery combines CSS to make a dynamic pull-down menu _jquery

Source: Internet
Author: User
Tags jquery library

When you want to place a large submenu in a limited navigation menu space, we generally use the form of a Pull-down menu to make up for the lack of space. This article will take you with a minimum of time, using jquery and CSS combined to create a dynamic drop-down menu.

Xhtml
The first is to introduce the jquery library into the head section of the page, which is necessary.

<script type= "Text/javascript" src= "Js/jquery.js" ></script> 

Then I use an unordered list to build the menu.

<ul class= "Menu" > 
  <li><a href= "#" > Home </a></li> 
  <li><a href= "#" > Service </a></li> 
  <li><a href= "#" > Case </a></li> 
  <li><a href= "#" > About </a></li> 
  <li><a href= "#" >BLOG</a></li> 
</ul> 

At a glance, looks very concise, because the Drop-down menu is closed, I also want to create a visual trigger Drop-down button, this article for the convenience of directly using a picture as a trigger button. and place the picture at the top of the menu list

 

Css
to create a CSS style for the menu, see the code:

. menu_head{border:1px solid #998675; background: #f30} 
menu{display:none; width:184px; border:1px solid #998675; Border-top:none} 
. Menu Li{list-style:none background: #493e3b} 
. menu Li a{padding:10px; display:block;color : #fff; Text-decoration:none} 
. Menu Li A:hover{font-weight:bold; 
Menu li.alt{background: #362f2d;} 

It is noteworthy that the. Menu Li.alt style is used to differentiate between odd and even line wrapping, as shown in the jquery code below.
JQuery
in the jquery code, first I want a drop-down menu row number to differentiate, to the even line one style: Alt. Then add a click Trigger event for the picture button, and you can toggle the Drop-down menu when the button is clicked.

$ (function () { 
  $ (". Menu Li:even"). AddClass ("alt"); 
  $ ("Img.menu_head"). Click (function () { 
    $ (". Menu"). Slidetoggle ("Fast");}); 
 

Attention , I use the jquery Slidetoggle method to slide the way to achieve the menu display and hide, the effect is very smooth.

The above is the sharing of jquery combined with CSS production dynamic Drop-down menu, I hope to help you learn.

Related Article

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.