Skip to content
This repository has been archived by the owner on Jul 3, 2018. It is now read-only.

Make smooth scroll cancellable #7

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Martin-Pitt
Copy link

Here is an implementation of smooth scroll that is cancellable by the user.

It was really annoying having my scroll constantly hijacked by the smooth scroll. (Macbook with trackpad - I was scrolling really slowly 馃槥)

To fix this, we use cause and effect. Programmatic scroll kicks in the scroll events, thus we remember what value we intended to smooth scroll to. If user initiates their own movement, this will show as a difference to our intended scroll position and therefore cancel our smooth scroll immediately.

On a side note:
That does make me wonder what would happen in a native snap scroll implementation world;聽What happens when your JS scrolls programmatically against a snap scroll enabled container, what does native snap scroll do in that situation?

@Martin-Pitt
Copy link
Author

By the way, forgot to add this: This definitely needs some cross-platform testing. I'll see what I can do, but any help is appreciated.

Have tried on a macbook (trackpad) with Chrome, Firefox & Safari so far.

@Martin-Pitt
Copy link
Author

This commit fails when scroll is body, e.g. it's relying on lastScrollObj vs lastObj as it needs to set its' own scroll event listener internally to check if user has moved.

I'm not sure how to proceed to untangle this. Should the caller pass lastObj as well into smoothScroll?

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

Successfully merging this pull request may close these issues.

None yet

2 participants