Simple jquery left navigation bar and page selection effect, jquery navigation bar

Source: Internet
Author: User

Simple jquery left navigation bar and page selection effect, jquery navigation bar

Here is to implement and select the left side of the navigation, this function needs to reference jquery

Left Navigation:

<Div class = "box"> <ul class = "menu"> <li class = "level1"> <a href = "# none" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow "> shirt </a> <ul class =" level2 "> <li> <a href =" # none "rel =" external nofollow "rel =" external nofollow "rel = "external nofollow" rel = "external nofollow "rel =" external nofollow "=" external nofollow "rel =" external nofollow "> short sleeve shirt </a> </li> <a href = "# none" rel = "external nofollow" rel =" external nofollow "rel =" external nofollow "rel = "external nofollow" rel = "external nofollow"> long-sleeved shirt </a> </li> <li> <a href = "# none" rel = "external nofollow" rel = "external nofollow "rel =" external nofollow "=" external nofollow "rel =" external nofollow "rel =" external nofollow "rel =" external nofollow "> short sleeve t-shirt </a> </li> <a href =" # none "rel =" external nofollow "rel =" external nofollow "rel = "external nofollow" rel = "external nofollow "rel =" external nofollow "rel =" external nofollow "> long-sleeved t-shirt </a> </li> </ul> </li> <li class =" level1 "> <a href = "# none" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow"> sweater </a> <ul class = "level2"> <li> <a href =" # none "rel =" external nofollow "rel =" external nofollow "rel = "external nofollow" rel = "external nofollow "rel =" external nofollow "rel =" external nofollow "> cardigan sweater </a> </li> <a href =" # none "rel =" external nofollow "rel =" external nofollow "=" external nofollow "rel =" external nofollow "rel =" external nofollow "rel =" external nofollow "rel = "external nofollow"> pullover sweater </a> </li> <a href = "# none" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow "rel =" external nofollow "=" external nofollow "rel =" external nofollow "> sports sweater </a> </li> <a href = "# none" rel = "external nofollow" rel =" external nofollow "rel =" external nofollow "rel = "external nofollow" rel = "external nofollow"> children's clothing sweater </a> </li> </ul> </li> <li class = "level1"> <a href = "# none" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow "rel =" external nofollow "rel = "external nofollow" rel = "external nofollow"> pants </a> <ul class = "level2"> <li> <a href = "# none" rel = "external nofollow" rel =" external nofollow "rel =" external nofollow "rel = "external nofollow" rel = "external nofollow"> shorts </a> </li> <li> <a href = "# none" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow "rel =" external nofollow "> casual pants </a> </li> <a href =" # none "rel =" external nofollow "=" external nofollow "rel =" external nofollow "rel =" external nofollow "rel =" external nofollow "rel = "external nofollow" rel = "external nofollow"> jeans </a> </li> <a href = "# none" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow" rel = "external nofollow "> free hot slice pants </a> </li> </ul> </div> js Code: <script type = "text/javascript"> // wait until the dom element is loaded. $ (document ). ready (function () {$ (". level1> "). click (function () {$ (this ). addClass ("current") // Add the "current" style to the current element. next (). show () // display the next element. parent (). siblings (). children (""). removeClass ("current") // The child element of the sibling element of the parent element <a> remove the "current" style. next (). hide (); // hide return false;}); </script>
/* reset */body{margin:0;padding:0 0 12px 0;font-size:12px;line-height:22px;font-family:"\5b8b\4f53","Arial Narrow";background:#fff;}form,ul,li,p,h1,h2,h3,h4,h5,h6{margin:0;padding:0;}input,select{font-size:12px;line-height:16px;}img{border:0;}ul,li{list-style-type:none;}a {color:#00007F;text-decoration:none;}a:hover {color:#bd0a01;text-decoration:underline;}.box {width: 150px;margin: 0 auto;}.menu{overflow:hidden;border-color: #C4D5DF;border-style: solid;border-width: 0 1px 1px;}/* lv1 */.menu li.level1 a{display: block;height: 28px;line-height: 28px;background:#EBF3F8;font-weight:700;color: #5893B7;text-indent: 14px;border-top: 1px solid #C4D5DF;}.menu li.level1 a:hover{text-decoration:none;}.menu li.level1 a.current{background:#B1D7EF;}/* lv2 */.menu li ul{overflow:hidden;}.menu li ul.level2{display:none;}.menu li ul.level2 li a{display: block;height: 28px;line-height: 28px;background:#ffffff;font-weight:400;color: #42556B;text-indent: 18px;border-top: 0px solid #ffffff;overflow: hidden;}.menu li ul.level2 li a:hover{color:#f60;}
<script type="text/javascript"> $(document).ready(function(){ $(".level2 a").each(function(){ $this = $(this); if($this[0].href==String(window.location)){ $this.addClass("hover"); } }); }); </script>


Jquery navigation: enter different pages, and the corresponding navigation text is selected

Hello! It takes some time. The simple method is to add the #1, #2, #3 identifier after each link address.
Then call the Jquery method.
$ (Function (){
Var url = document. location. href;
Var menuId = url. split ('#') [1];
If (menuId = null)
{
MenuId = 1;

}
Var num = 0;
$ ("# Aaa ul"). find ("li"). each (function (){
Num ++;
If (num = menuId)
{
$ (This). addClass ("current ");
}
});

});

Hope to help you!

How does jquery control the navigation menu of the current page?

For example, the <div class = "nav"> <a href = "index.html"> homepage </a> <a href = "product.html"> product </a>
The following html content:
<Div class = "main">
<Div class = "content"> homepage content </div>
<Div class = "content"> product content </div>
<Div class = "content"> case center content </div>
</Div>
As for class = "content", you can add it yourself to facilitate jQuery's acquisition, without this style class.
<Script type = "text/javascript">
$ (Document). ready (function ()
{
Var tabs =$ ('. nav> ');
Var cons = $ ('. main> div. content ');

Tabs. first (). addClass ("now"). show (); // The first display by default
Cons. first (). show (). nextAll (). hide (); // The first display is displayed by default, and others are hidden.
Tabs. each (function (index ){
$ (This). mouseover (function (){
$ (This). addClass ("now"). siblings (). removeClass ("now ");
Cons. eq (index). show (). siblings (). hide ();
});
});

});
</Script>

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.