mudin / magic-scroll

Apple Magic Mouse scrolling effect for normal mouses
https://mudin.github.io/magic-scroll/
MIT License
44 stars 4 forks source link

Keep scroll position done with window.scroll() #2

Closed laugre closed 4 years ago

laugre commented 4 years ago

Hi and thx a lot for this work :) I'm using it in my Gatsby website and it works like magic !

Sometimes I have to perform a smooth goto on my web page with this method window.scroll({ top: elemPos + offSet, left: 0, behavior: 'smooth' });

And when I take back the control with my mouse, scroll position go back to last scroll position before my goto.

Do you know how to keep my scroll position ? Thx

mudin commented 4 years ago

@laugre Hello I am happy that you like it. I am not sure if I understand you correctly. Have you tried to add current option?

laugre commented 4 years ago

What do you mean by current option ? I didn't find your documentation.

mudin commented 4 years ago

Sorry there is no documentation

let magicScroll = new MagicScroll({
  speed: 80,
  smooth: 12,
  current: 200 // <-- here
});
laugre commented 4 years ago

My problem is I have a "goto top" button at the end of my web page to automatically scroll to the top of my page. If I scroll down to the end and click my button the page well scroll to top with my method window.scroll({ top: 0, left: 0, behavior: 'smooth' }); But I use again mouse wheel, the page first scroll to the end before reacting to mouse wheel. By using window.scroll(...) the position is not saved by your MagicScroll.

mudin commented 4 years ago

@laugre Okay I got it now. can you try this? magicScroll.pos = window.document.scrollingElement.scrollTop

udoro commented 4 years ago

Hello, thanks for the nice work. After using this on a website, I noticed exactly the same issue pointed out by Laugre. Here is a video to show the problem:

Where should I use this solution you provided? magicScroll.pos = window.document.scrollingElement.scrollTop

I noticed the same problem in your demo here: https://jsfiddle.net/mudin/2nstb5pf/ after scrolling, if you want to take control by dragging on the scrollbar before the scrolling stops, it will revert to it's last position.

https://www.loom.com/share/c4cf9754d9a147ec877aaeddafb1e40a