-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
feat: add lazy option to allow recalculating targets #388
feat: add lazy option to allow recalculating targets #388
Conversation
Anybody is here? |
Should I update documentation? |
src/scrollTo.js
Outdated
if (x) { | ||
targetX = | ||
cumulativeOffsetElement.left - cumulativeOffsetContainer.left + offset | ||
diffX = targetX - initialX | ||
} | ||
if (y) { | ||
targetY = | ||
cumulativeOffsetElement.top - cumulativeOffsetContainer.top + offset | ||
diffY = targetY - initialY | ||
} |
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.
I would refactor this since calculations are same as
Lines 196 to 207 in eb11b5f
initialY = scrollTop(container) | |
targetY = | |
cumulativeOffsetElement.top - cumulativeOffsetContainer.top + offset | |
initialX = scrollLeft(container) | |
targetX = | |
cumulativeOffsetElement.left - cumulativeOffsetContainer.left + offset | |
abort = false | |
diffY = targetY - initialY | |
diffX = targetX - initialX |
Refactoring both places to use a function would likely be a cleaner approach - since if we ever need to change how the target is calculated, it needs to be done in a single spot.
Something like recalculateTargets
, or something better perhaps.
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.
Should I do it or you will?
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.
I probably won't be able to for at least a few weeks, so if you are able to do it, that would be perfect!
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.
Done
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.
Added suggestions (I'm about to commit those directly - so no action required)
🎉 This PR is included in version 2.20.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hello!
I ran into a problem when I was trying to use this lib on a dynamically growing container. Figuratively speaking, at the start of the scroll, the height of the container was 500px, and at the end it could reach 5000px. Thus, the initially set position was strongly shifted down, but the scrollTo did not know about this and scrolled to the wrong place. This PR solves this problem.