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

Use element.getBoundingClientRect().top rather than element.offsetTop #38

Open
lukeify opened this issue Nov 16, 2015 · 1 comment
Open

Comments

@lukeify
Copy link

lukeify commented Nov 16, 2015

Line 99:

sectionOffsets[sections[i].id] = sections[i].offsetTop;

offsetTop fetches the element relative to the top of the nearest relatively positioned element, not relative to the document. If you by chance have a relatively-positioned element in between your navbar and your sections, this causes the scrollto functionality to scroll to the incorrect location.

This can be fixed by using getBoundingClientRect().top (or .y) instead:

sectionOffsets[sections[i].id] = sections[i].getBoundingClientRect().top;

Perhaps add a setting for DOM-absolute or relative offsets also, if you consider this a breaking change (I don't think it should be, but I can't test all use cases).

Would you be able to fix this (alternatively I can make a PR) and push a new release to packagist? Thanks!

@lukeify
Copy link
Author

lukeify commented Nov 29, 2015

Any progress on this? @jbutko

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

No branches or pull requests

1 participant