Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <nav class="postNav">
- <ul>
- <li class="active"><a href="#pageHeader">link to header</a></li>
- <li><a href="#one">link to other posts</a></li>
- <li><a href="#two">link to other posts</a></li>
- <li><a href="#three">link to other posts</a></li>
- <li><a href="#four">link to other posts</a></li>
- <li><a href="#five">link to other posts</a></li>
- </ul>
- </nav>
- var navs = $('.postNav'),
- first = navs.first(),
- active = first.find('.active a').attr('href'),
- anchrs = navs.not(first);
- anchrs.find('li').removeClass('active');
- anchrs.find('a[href=' + active + ']').parent().addClass('active');
- var nav = $('.postNav'),
- first = nav.filter(':eq(0)'),
- notF = nav.filter(':gt(0)'),
- index = first.find('.active').index();
- notF.each(function(){
- $(this).find('li').removeClass('active').eq(index).addClass('active');
- });
- var index = $(".postNav .active").index();
- $(".postNav ul").each(function() {
- $(this).children("li").removeClass("highlight").eq(index)
- .not(".active").addClass("highlight");
- });
- <nav class="postNav">
- <ul>
- <li class="header active"><a href="#pageHeader">link to header</a></li>
- <li class="one"><a href="#one">link to other posts</a></li>
- <li class="two"><a href="#two">link to other posts</a></li>
- <li class="three"><a href="#three">link to other posts</a></li>
- <li class="four"><a href="#four">link to other posts</a></li>
- <li class="five"><a href="#five">link to other posts</a></li>
- </ul>
- </nav>
- $(function() {
- $('li').on('click', function() {
- $('.active').removeClass('active');
- $('.'+$(this).attr('class')).addClass('active');
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement