jquery CSS main Menu style jump

Source: Internet
Author: User

The effect is quite common: the main course of a Web page has a default style (such as a style), and when the mouse passes through a menu item, it applies a style (such as a B-style), and when the mouse clicks on a menu item, it applies a B-style, The rest of the menu items are stripped of the B style and the default a style is applied. After trying to write a relatively simple code, save it for later use.

HTML code:

<div id= "MenuBar" >    <ul>            <li>Home</li>            <li>Download</li>            <li>Documentation</li>            <li>Community</li>            <li>success stories</li>            <li>News</li>             <li>Events</li>            <li>About</li>               </ul>    </div>

CSS code:

#menuBar {clear:both;width:1200px;margin:0 auto;color: #efefef; font-family:arial;font-size:18px;} #menuBar ul{list-style:none;height:55px;margin:0px;padding:0px;}. Beforeclick{float:left;width:150px;text-align:center;line-height:55px;height:55px;background-image:url (Welcome %20to%20python.org_files/20141021190636.png); background-repeat:repeat-x;margin-top:10px;}. beforeclick:hover{background-color:3776ab;border:1px solid #aaa; height:53px;line-height:53px;width:148px; Background-image:none;cursor:pointer;}. clickedmenu{background-color:3776ab;border:1px solid #aaa; height:53px;line-height:53px;width:148px; Background-image:none;cursor:pointer;}

JS Code:

<script>$ (function () {$ ("#menuBar ul Li"). each (function () {        $ (this). addclass ("Beforeclick");//At the very beginning, Make all nodes add Beforeclick style    }); $ (function () {$ ("#menuBar ul Li"). each (function (i) {$ (this). Click (function () {$ (this). Siblings ("Li"). Removeclass (" Clickedmenu "); Let the rest of the sibling nodes get rid of the clickedmenu style, that is, the menu style after the click of $ (this). Siblings ("Li"). addclass ("Beforeclick"); Let the remaining sibling nodes add the style beforeclick$ (this) before the click. addclass ("Clickedmenu");//Add a clickedmenu style to the current node. })});}) </script>

1. Initial state:

2, the mouse through a menu item when the state:

3, the mouse click on a menu, and the mouse through other menu items when the state:

3. When you click another menu again, the style continues to change:


jquery CSS main Menu style jump

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.