Skip to content

Fix rounding error in scroll behavior #1383

Closed
@jhildenbiddle

Description

@jhildenbiddle

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)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions