kalponikoronno

Jquery active highlight menu 3

Aug 27th, 2014
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.17 KB | None | 0 0
  1. example : https://dl.dropboxusercontent.com/u/155522840/activemenu/index.html
  2. css
  3. ============================
  4. .mainmenu_area{margin:50px auto;width:500px;}
  5. ul{margin:0;padding:0;list-style:none;}
  6. ul li{float:left; background:#2181C2; margin-right:1px; }
  7. ul li a{display:block;padding:5px 15px;font-size:15px;color:#fff;}
  8. ul li a:hover{text-decoration:none;color:#000;}
  9. ul li.active{ background:#6CBD3E;}
  10. ul li.active a{ color:#fff; cursor:default;}
  11.  
  12. html
  13. ============================
  14. <div class="mainmenu_area">
  15.     <ul>
  16.         <li class="active"><a href="index.html">Home</a></li>
  17.         <li><a href="product.html">Product</a></li>
  18.         <li><a href="about.html">About</a></li>
  19.         <li><a href="contact.html">Contact</a></li>
  20.     </ul>
  21. </div>
  22.  
  23.  
  24.  
  25.  
  26. jquery
  27. ============================
  28. $(document).ready(function(){
  29.         var str=location.href.toLowerCase();
  30.        
  31.         $(".mainmenu_area ul li a").each(function() {
  32.                 if (str.indexOf(this.href.toLowerCase()) > -1) {
  33.                          $("ul li.active").removeClass("active");
  34.                         $(this).parent().addClass("active");
  35.                         }
  36.                        
  37.         });
  38. })
Advertisement
Add Comment
Please, Sign In to add comment