-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement relative scroll time from distance #167
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this PR Luis, I left some comments, let me know what you think!
src/smoothscroll.js
Outdated
@@ -221,6 +222,12 @@ function polyfill() { | |||
method = scrollElement; | |||
} | |||
|
|||
const maxDistance = Math.max(Math.abs(x - startX), Math.abs(y - startY)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a comment on top of this two lines of math operations (not that is unclear what they do), it will help people reading the code for the first time a lot, to understand the reasoning and why we are doing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, let put it in 2 lines and better for others to modify it in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, feel free to suggest a different explanation, comments, etc...
Also, I added the animation speed which is 1 pixel/ms. It will make it easier to modify it you think that another value matches better the native bahaivour.
@jeremenichelli , what do you think about the changes? Please, let me know what else to change. Thanks :) |
Sorry for the late response Luis, I've been caught up with personal stuff. One thing I notice is you are using const and in the build project we don't have transpiling to support old browsers, so I would change those to vars for now. |
The SCROLL_TIME is a magic number of 468ms.
I would like to use this great polyfill in https://github.com/luispuig/react-snaplist-carousel but this time is too long.
My first thought was making it configurable but then I read #140 and #65
I agree
Here I got the idea of using the scroll distance to calculate the scroll time.
I set up some min and max scroll times.
Left: Firefox, Center: Chrome, Right: Safari using the polyfill
Chrome makes the animation much faster than Firefox and different ease. So, I tried to adjust something in the middle.
P.D: Great work with this polyfill :D