简体   繁体   中英

Smooth scrolling link effect issue with vertical menu

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!

修复您的 if 语句:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM