Kevin Powell - CommunityKP-C
Kevin Powell - Community11mo ago
5 replies
Gulian

Infinite carousel gets stuck when scrolling too fast

I've been working on this draggable/scrollable infinite carousel for a few hours but I ran into an issue. It seems like whenever my if statements hits within infiniteScroll, and the user scrolls 'too fast', the if statement triggers again before carousel.scrollLeft() has updated, causing the carousel.scrollLeft() to get overwritten.

I've attached a screenshot showing the values of carousel.scrollLeft(), where we can see that it 'teleports' back and forth a couple of times, causing it to get stuck.

How could I prevent this from happening?

This problem occurs more often when using shift + scrolling (horizontal scrolling)

https://codepen.io/Gulian256/pen/GgRrLeJ

PS This is my first post here, any feedback to make the post/question clearer would be appreciated!
Screenshot_2025-03-01_173924.png
CodePenJulian
...
Untitled
Was this page helpful?