ashthornton / asscroll

Ash's Smooth Scroll 🍑
MIT License
947 stars 27 forks source link

Scroll jumps up when enabling #72

Open iamlinkus opened 2 years ago

iamlinkus commented 2 years ago

Hey, I'm trying to find out what causes a scroll jump up on a project I'm working on.

I have a focus section which when reached locks the scroll using asscroll.disable and once certain criteria are met (scrolled enough while being locked) unlocks the scroll using asscroll.enable with restore: true.

I'm dependent on the wheel event while the viewport is locked as that's what eventually triggers the unlock, so the user usually is scrolling the mousewheel (or trackpad) the moment when the scroll unlocks.

Now the problem I'm having is that the scroll position (or rather targetPos of asscroll) intermittently jumps upwards. I tried debugging it using breakpoints, but after half a day I did not get anywhere.

I have a theory that because asscroll handles the wheel event, once asscroll is enabled, the wheel event fires before the body height is restored and that probably confuses asscroll as it sets the targetPos (which I'm unable to set manually because it does not have a setter) higher in the page.

I've prepared an example codepen from the forked ASSCroll Basic Demo here: https://codepen.io/linkus/pen/oNeRQga?editors=1111

It's very intermittent, but you can replicate the issue by scrolling slowly down while the viewport is locked.

I've also made a video of the issue (despite me scrolling down only, it jumps up when unlocking):

https://user-images.githubusercontent.com/16874184/143063999-b5508e10-81de-4aa5-a23d-507f3097f1d7.mp4

@ashthornton if you could have a look it would be extremely helpful! Thanks!