locomotive-scroll
locomotive-scroll copied to clipboard
Option to cancel scroll event - like preventDefault()
Is your feature request related to a problem? Please describe. I have a small intro animation achieved by automatically scrolling down one viewport after page load to a short text with lerp effects. But now I have an empty space of one viewport above this text the user could scroll up to. And I want to prevent that the user can scroll further up than a certain scroll.Y position.
Describe the solution you'd like I'd like the ability to cancel the scroll effect under certain conditions. As I would do with event.preventDefault() on the native scroll event. But as far as I can tell I have no access to the original event processed by locomotive-scroll, nor any method to do this. Maybe I've missed something?
Describe alternatives you've considered I've tried using scrollTo to scroll back if the user scrolled too far up, but that results in a lot of stuttering and conflicting animations. I also tried to animate the text on my own on page load but again there are animation conflicts if the user starts scrolling during the animation and locomotive-scroll is also applied to the text. Last I tried to remove the empty space after the scrollTo happened but that of course caused layout shifts and many other problems.
Thanks for considering/helping. Chris
Hey, have you tried the stop()
method? This would allow you to stop the scroll and its events. Then you can use .start()
to resume
Hi devenini, yes, I tried stop()
; but this not only stops scrolling but also disables the scroll event detection in locomotive-scroll, so I cannot resume with start()
when the user is scrolling down instead of up.