locomotivemtl / locomotive-scroll

🛤 Detection of elements in viewport & smooth scrolling with parallax.
https://locomotivemtl.github.io/locomotive-scroll
MIT License
7.56k stars 1.11k forks source link

Detect scroll position #413

Open zoombree opened 2 years ago

zoombree commented 2 years ago

Hi All , I have a jquery snippet used to hide/show navbar based on scroll position, unfortunately, it stops working when using "LOCOMOTIVE"

this is the main var used to build logic: var position = $(window).scrollTop()

thanks for your time & support.

Azrael83 commented 2 years ago

Hi,

try something like that : if (instance) scroll is superior at "amount of pixel you want" do something, else do something else.

I have made a sticky menu like that.

let DynamicMenu = document.getElementById("Show-hide-menu");

    scroll.on("scroll", (instance) => {
    if (instance.scroll.y > 360) {
    DynamicMenu.classList.add('show-menu'); 
    }
    else {
    DynamicMenu.classList.remove('hide-menu');
    }