-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent loop from animated scrolling
It happened quite a lot on touch devices, that when crossing boundary of genuine items, it would reposition the slider but with animation on. It happened because, yes, I shifted the slider and only then enabled the animations again, even in a setTimeout, but that in and of itself doesn't guarantee that the animation enabling runs after the shift. The event loop can queue multiple macrotasks (also setTimeout's) before it repaints and that's what was happening in my case - the shift was scheduled but so was also enabling the animations. The solution was to make sure I wait for after the next paint before re-enabling animations, which I achieved with a combo of requestAnimationFrame and setTimeout in this order. requestAnimationFrame makes sure my code is executed just before the next paint, where the shift is going to happen, and setTimeout "jumps over" to the next frame where and only then the animation is enabled again.
- Loading branch information
Showing
3 changed files
with
25 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters