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 rounding error in scroll behavior #1383

Closed
jhildenbiddle opened this issue Oct 2, 2020 · 0 comments · Fixed by #1384
Closed

Fix rounding error in scroll behavior #1383

jhildenbiddle opened this issue Oct 2, 2020 · 0 comments · Fixed by #1384
Assignees

Comments

@jhildenbiddle
Copy link
Member

Bug Report

Scroll implementation does not account for floating point values returned from getBoundingClientRect():

end: el.getBoundingClientRect().top + window.pageYOffset - offset,

The result is that scroll event end values will be 1px less than expected because some browsers ignore the value after the decimal point (e.g. 1234.567 is process as 1234 instead of being rounded up to 1235). Values returned from getBoundingClientRect() should be wrapped in Math.round() to ensure consistent behavior.

Steps to reproduce

I noticed this bug on the docsify-themeable website while testing the docsify-sidebar-collapse plugin for a separate issue (I'm not adding this plugin to the docsify-themeable website). I noticed that when some headings were scrolled to the top of the screen they were 1px away from the top edge.

Mention the docsify version in which this bug was not present (if any)

All versions up to current (4.11.6)

@jhildenbiddle jhildenbiddle self-assigned this Oct 2, 2020
jhildenbiddle added a commit that referenced this issue Oct 2, 2020
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 a pull request may close this issue.

1 participant