Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. <nav class="postNav">
  2. <ul>
  3. <li class="active"><a href="#pageHeader">link to header</a></li>
  4. <li><a href="#one">link to other posts</a></li>
  5. <li><a href="#two">link to other posts</a></li>
  6. <li><a href="#three">link to other posts</a></li>
  7. <li><a href="#four">link to other posts</a></li>
  8. <li><a href="#five">link to other posts</a></li>
  9. </ul>
  10. </nav>
  11.  
  12. var navs = $('.postNav'),
  13. first = navs.first(),
  14. active = first.find('.active a').attr('href'),
  15. anchrs = navs.not(first);
  16.  
  17. anchrs.find('li').removeClass('active');
  18. anchrs.find('a[href=' + active + ']').parent().addClass('active');
  19.  
  20. var nav = $('.postNav'),
  21. first = nav.filter(':eq(0)'),
  22. notF = nav.filter(':gt(0)'),
  23. index = first.find('.active').index();
  24.  
  25. notF.each(function(){
  26. $(this).find('li').removeClass('active').eq(index).addClass('active');
  27. });
  28.  
  29. var index = $(".postNav .active").index();
  30. $(".postNav ul").each(function() {
  31. $(this).children("li").removeClass("highlight").eq(index)
  32. .not(".active").addClass("highlight");
  33. });
  34.  
  35. <nav class="postNav">
  36. <ul>
  37. <li class="header active"><a href="#pageHeader">link to header</a></li>
  38. <li class="one"><a href="#one">link to other posts</a></li>
  39. <li class="two"><a href="#two">link to other posts</a></li>
  40. <li class="three"><a href="#three">link to other posts</a></li>
  41. <li class="four"><a href="#four">link to other posts</a></li>
  42. <li class="five"><a href="#five">link to other posts</a></li>
  43. </ul>
  44. </nav>
  45.  
  46. $(function() {
  47. $('li').on('click', function() {
  48. $('.active').removeClass('active');
  49. $('.'+$(this).attr('class')).addClass('active');
  50. });
  51. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement