Skip to content
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

fix(useScroll): account for rounding errors when calculating arrivedState #2051

Merged
merged 1 commit into from Aug 6, 2022
Merged

fix(useScroll): account for rounding errors when calculating arrivedState #2051

merged 1 commit into from Aug 6, 2022

Conversation

curtgrimes
Copy link
Contributor

Description

Sometimes when zooming the page to sizes other than 100% and scrolling a
container all the way to the bottom right, the calculation for
arrivedState.right and arrivedState.bottom would incorrectly say
false. This is due to a rounding error because scrollTop is a
non-rounded number, while scrollHeight and clientHeight are rounded.

Using the MDN documentation on Element.scrollHeight as guidance,
this commit factors in a 1px margin of error to more accurately
calculate arrivedState.right and arrivedState.bottom.

fix #2047


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

…tate

Sometimes when zooming the page to sizes other than 100% and scrolling a
container all the way to the bottom right, the calculation for
`arrivedState.right` and `arrivedState.bottom` would incorrectly say
`false`. This is due to a [rounding error][] because `scrollTop` is a
non-rounded number, while `scrollHeight` and `clientHeight` are rounded.

Using the MDN documentation on `Element.scrollHeight` as guidance,
this commit factors in a 1px margin of error to more accurately
calculate `arrivedState.right` and `arrivedState.bottom`.

[rounding error]: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#determine_if_an_element_has_been_totally_scrolled

fix #2047
@antfu antfu merged commit 53a209e into vueuse:main Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useScroll - right and bottom arrived not working in Desktop mode
2 participants