Smooth scrolling link effect issue with vertical menu

时光怂恿深爱的人放手 提交于 2019-12-14 04:25:30

问题


I'm trying to fix a problem on this template: https://codepen.io/eksch/pen/xwdOeK

The highlighting effect on the navigation menu only works on a reduced browser height, if I resize the window to full screen (https://codepen.io/eksch/full/xwdOeK) and scroll down to section 7, the link on the navigation menu will not be highlighted. (I'm viewing from a 27 in imac)

In the javascripts, I believe this funciton controls the link highlight: $(window).scroll(function() { var scrollDistance = $(window).scrollTop();

    // Show/hide menu on scroll
    //if (scrollDistance >= 850) {
    //      $('nav').fadeIn("fast");
    //} else {
    //      $('nav').fadeOut("fast");
    //}

    // Assign active class to nav links while scolling
    $('.page-section').each(function(i) {
            if ($(this).position().top <= scrollDistance) {
                    $('.navigation a.active').removeClass('active');
                    $('.navigation a').eq(i).addClass('active');
            }
    });
}).scroll();

Is there a way that I change the code to adapt to all screen size? And how should I make the section interactive with bootstrap?

I'm stil new to front-end development, appriciate for any help!


回答1:


Fix your if statement:

if ($(this).position().top - $(this).height() <= scrollDistance)


来源:https://stackoverflow.com/questions/54857742/smooth-scrolling-link-effect-issue-with-vertical-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!