Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headroom.js together with Locomotive Scroll #396

Open
JoBlast447 opened this issue Jan 11, 2022 · 2 comments
Open

Headroom.js together with Locomotive Scroll #396

JoBlast447 opened this issue Jan 11, 2022 · 2 comments

Comments

@JoBlast447
Copy link

JoBlast447 commented Jan 11, 2022

Hi, I am developing a project in which I use Headroom.js.

Now I have integrated Locomotive Scroll successfully but Headroom.js no longer works.

In Headroom.js there is an option called "scroller" where you enter an element to listen to scroll events on, defaults to "window", I have tried to enter "[data-scroll-container]" or "[data-scroll-section]" which are the containers that allow Locomotive to recreate the smooth scroll effect, but it doesn't work.

Is there anyone who has had a similar experience and can help me?
Thank you in advance for a kind reply!

@WickyNilliams
Copy link
Owner

It does not take a selector, but rather an actual element:

new Headroom({
  scroller: document.querySelector("[data-scroll-container]")
})

Hope that helps

@JoBlast447
Copy link
Author

JoBlast447 commented Jan 11, 2022

Hi,
Thank You for your feedback but unfortunately it doesn't work

now for Headroom.js i have this:

(function() {
    var header = new Headroom(document.querySelector("#header"), {
        scroller: document.querySelector("[data-scroll-container]"),
        tolerance: 5,
        offset : 75,
        classes: {
          initial: "animated",
          pinned: "slideDown",
          unpinned: "slideUp",
        },
    });
    header.init();
}());

and for Locomotive Scroll i have this:

const scroll = new LocomotiveScroll({
    el: document.querySelector('[data-scroll-container]'),
    smooth: true,
});

if I remove the Locomotive Scroll part then Headroom.js works again

the HTML code looks like this:

<div data-scroll-container>
    <section data-scroll-section>
        <header id="header">
            .....
        </header>
        .....
    </section>
</div>

I tried to move the header outside the Locomotive containers but nothing works.
if anyone has a solution it is welcome
Thanks

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

No branches or pull requests

2 participants