Highlight Menu Item when Scrolling Down to Section

前端 未结 5 703
天命终不由人
天命终不由人 2020-11-29 02:22

I know this question have been asked a million times on this forum, but none of the articles helped me reach a solution.

I made a little piece of jquery code that hi

5条回答
  •  醉酒成梦
    2020-11-29 02:58

    In this line:

     $('#navigation > ul > li > a').attr('href', id).addClass('active');
    

    You are actually setting the href attribute of every $('#navigation > ul > li > a') element, and then adding the active class also to all of them. May be what you need to do is something like:

    $('#navigation > ul > li > a[href=#' + id + ']')
    

    And select only the a which href match the id. Make sense?

提交回复
热议问题