Skip to content
This repository was archived by the owner on Jul 25, 2022. It is now read-only.

Bug on scroll and click #110

Open
hevertonsb opened this issue Jun 5, 2021 · 1 comment
Open

Bug on scroll and click #110

hevertonsb opened this issue Jun 5, 2021 · 1 comment

Comments

@hevertonsb
Copy link

hevertonsb commented Jun 5, 2021

Hi, sorry about my english, but i hope you understand my problem.

I'm using scrollnav.js plugin on this page (http://edf-re.web36f05.kinghost.net/quem-somos/edf-mundo/), but I'm facing a bug.

On click and scroll the content is not aligned with the vertical menu. Can anybody help me? I've tried changing some parameters, but nothing solved.

The calling code for the plugin is this:

if (1 < $('.section-title').length) {
    $('#content').scrollNav({
        sections: '.section-title',
        subSections: true,
        sectionElem: 'div',
        showHeadline: false,
        showTopLink: false,
        scrollOffset: $('#header').outerHeight(),
        fixedMargin: $('#header').outerHeight()
    });

    $('body').addClass('has-scroll-nav');

    $(window).scroll(function() {
        var limit = $('#content').offset().top + $('#content').height();
        var scrollTop = $(document).scrollTop() + $('.scroll-nav .scroll-nav__wrapper').outerHeight() + $('#header').outerHeight();
        var difference = scrollTop - limit;

        if (limit < scrollTop) {
            $('.scroll-nav .scroll-nav__wrapper').css('margin-top', 0 - difference);
        }
        else  {
            $('.scroll-nav .scroll-nav__wrapper').css('margin-top', 0);
        }
    });
}

I would like when clicking or scrolling, the title was visible on the page. Thanks

@jimmynotjim
Copy link
Owner

It looks like you're using the older version of ScrollNav, make sure you're referencing the docs here https://scrollnav.com/v2/. My initial guess was you need to modify the scrollOfset to account for the sticky header but it looks like you're doing that. It could be possible the header isn't completely rendered and so the outer height is being miscalculated. You might have to wait for that before initializing the plugin.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants