idiotWu / smooth-scrollbar

Customizable, Extendable, and High-Performance JavaScript-Based Scrollbar Solution.
https://idiotwu.github.io/smooth-scrollbar/
MIT License
3.31k stars 384 forks source link

Incorrect behavior of the smooth scroll #240

Closed mrWilson123 closed 3 years ago

mrWilson123 commented 4 years ago

Hi,

I'm trying to get smooth scrolling to work properly, but unfortunately, I can't handle it myself (sorry, I'm pretty new of this). I'm using TweenMax. If you look at it https://codepen.io/Siilionu/pen/poJraMM you will see that it is not working properly. Clicking on the link will move it chaotically. Also, if you click on the link multiple times, the page will move up and down, though it shouldn't.

Hopefully, someone can help me with this. Thank you.

idiotWu commented 4 years ago

I'd suggest you use the .scrollTo() method with custom easing functions which would perfectly meet your needs.

idiotWu commented 4 years ago

Also, instead of using$(href).offset().top which returns the relative offset to the top side of window, you need to calculate the relative position to the scrollbar container like:

top = $(href).offset().top - $(container).offset().top
mrWilson123 commented 4 years ago

Hi, @idiotWu. Thank you for your answer. Can you please show me a real code example because I still can't get it to work properly. :(

https://codepen.io/Siilionu/pen/poJraMM

idiotWu commented 4 years ago

To do it quickly, you can change topY to

topY = $(href).offset().top - $('#scroll-container > .scroll-content').offset().top