locomotivemtl / locomotive-scroll

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

Option to cancel scroll event - like preventDefault() #359

Open odysseuscm opened 2 years ago

odysseuscm commented 2 years ago

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

devenini commented 2 years ago

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

odysseuscm commented 2 years ago

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.