kalponikoronno

Jquery active highlight menu 2

Aug 27th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.13 KB | None | 0 0
  1. css
  2. ====================================
  3. .nav {background: none repeat scroll 0 0 #da5d00;
  4. margin: 200px auto;
  5. width: 270px;}  
  6. .nav ul {margin:0;padding:0;list-style:none;}    
  7. .nav ul li {float: left;
  8. border-right: 1px solid#fff;}  
  9. .nav ul li:last-child {border-right: 0px solid#fff;}    
  10. .nav ul li a {color: #fff;
  11. display: block;
  12. font-size: 20px;
  13. padding: 10px 15px;
  14. text-decoration: none;}    
  15. .nav ul li a:hover {background:#333;}  
  16. .nav ul li .active {background:#1C6959;}
  17.  
  18. html
  19. ===========================================
  20. <div class="nav">
  21.    
  22.     <ul>
  23.         <li><a href="index.html">Home</a></li>
  24.         <li><a href="active1.html">Contact</a></li>
  25.         <li><a href="active2.html">About</a></li>
  26.        
  27.     </ul>
  28.    
  29. </div>
  30.  
  31. jquery
  32. ============================================
  33. $(document).ready(function(){      
  34.     $(function() {
  35.          var pgurl = window.location.href.substr(window.location.href
  36.     .lastIndexOf("/")+1);
  37.          $(".nav ul li a").each(function(){
  38.               if($(this).attr("href") == pgurl || $(this).attr("href") == '' )
  39.               $(this).addClass("active");
  40.          })
  41.     });
  42. });
  43.  
  44. source: http://andornagy.com/active-class-navigation-menu/
Advertisement
Add Comment
Please, Sign In to add comment