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

Is it possible to specify the scroll container? #66

Closed
mtskf opened this issue Nov 10, 2019 · 5 comments
Closed

Is it possible to specify the scroll container? #66

mtskf opened this issue Nov 10, 2019 · 5 comments

Comments

@mtskf
Copy link

mtskf commented Nov 10, 2019

Hi there, thanks for the awesome script!
I'm just wondering if we could apply lax only inside a scrollable div elements.
I'd appreciate if you could advise! Thanks :)

@mtskf mtskf changed the title Is it possible to apply lax to the scroll in side a specific div instead of html/body? Is it possible to apply lax to the scroll inside a specific div instead of html/body? Nov 10, 2019
@mtskf mtskf changed the title Is it possible to apply lax to the scroll inside a specific div instead of html/body? Is it possible to specify the scroll container? Nov 10, 2019
@alexfoxy
Copy link
Owner

Hey - glad you like it :)

How many elements do you have? If you only have one you can bind to the scroll events from that window e.g:

window.onload = function() {
	lax.setup() // init
        const el = document.getElementById("scrollableDiv") // Find your scrollable element
 
	const updateLax = () => {
		lax.update(el.scrollTop) // pass in the elements scrolled position
		window.requestAnimationFrame(updateLax)
	}

	window.requestAnimationFrame(updateLax)
}

Hope that helps!

@mtskf
Copy link
Author

mtskf commented Nov 12, 2019

Thanks @alexfoxy , you are champion!

@Meidanmor
Copy link

Meidanmor commented Jan 13, 2022

I can't make it work :/
can you please help me?
This is what I tried :

window.onload = function () {
    lax.init()
        const el = document.querySelector(".parallax") // Find your scrollable element
	const updateLax = () => {
		lax.update(el.scrollTop) // pass in the elements scrolled position
		window.requestAnimationFrame(updateLax)
	}
	window.requestAnimationFrame(updateLax)
    // Add a driver that we use to control our animations
      lax.addDriver(
        "scrollY",
        function () {
          return document.documentElement.scrollTop;
        },
        { frameStep: 1 }
      );
  }

What am I doing wrong?

@arthurdenner
Copy link
Contributor

arthurdenner commented Jan 13, 2022

@Meidanmor, sorry if I misunderstood what you're trying to achieve, I'm not 100% up-to-date with lax but:

  • Shouldn't the value for the scrollY driver be el.scrollTop instead of the document?
  • It seems like lax.update is not a function anymore, I'm not sure if there's a replacement for it.

@Meidanmor
Copy link

@arthurdenner Thank you!
You are clearly right , I just needed to change the document within the driver
return document.documentElement.scrollTop;
to
return el.scrollTop;

full code:

window.onload = function () {
    lax.init()
   const el = document.querySelector(".parallax") // Find your scrollable element
 
    // Add a driver that we use to control our animations
      lax.addDriver(
        "scrollY",
        function () {
          return el.scrollTop;
        },
        { frameStep: 1 }
      );
}

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

4 participants