Skip to content

Conversation

@IHIutch
Copy link

@IHIutch IHIutch commented Feb 11, 2025

Summary

Rather than recursively walking up the DOM tree which could be quite deep, el.getBoundingClientRect().top + window.scrollY provides the position of the element on the page immediately.

Related issue

Related pull requests

Updates the work on this PR: #5878

Preview link

Preview link

Problem statement

The current implementation walks up the DOM tree which could be extremely deep and expensive to do

Solution

Uses a more optimal method to detect the vertical position of an element on a page

Major changes

n/a

Testing and review

Updates tests to match the fact that JSDOM cannot get window.scrollY or el.getBoundingClientRect().top. By using getBoundingClientRect() we cannot simply add up the offsetTop values of elements to verify the scroll position.

@IHIutch IHIutch changed the title Get element offset without walking up the DOM tree Get heading/TOC offset without walking up the DOM tree Feb 11, 2025
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.

1 participant