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

Support a tree of scrollable elements #11

Merged
merged 3 commits into from Feb 14, 2020
Merged

Conversation

calvellido
Copy link
Owner

This is a refactor based on what was proposed by @aFarkas in #3, traversing a tree of potential scrollable elements.

This closes #3

Copy link
Owner Author

@calvellido calvellido left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@calvellido calvellido merged commit d07c4a2 into master Feb 14, 2020
@calvellido calvellido deleted the jv-3-scrolling-elements branch February 14, 2020 15:34
parent = parent.parentNode;
}
parent = document.scrollingElement;
scrollableElements.push([parent, parent.scrollTop, parent.scrollLeft]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI to anyone in the future that if document.scrollingElement doesn't exist, this will throw an error. Example would be in Internet Explorer or when testing with jest or anything that uses jsdom.

@calvellido As document.scrollingElement is document.documentElement by default (https://developer.mozilla.org/en-US/docs/Web/API/document/scrollingElement), would it make sense to fall back to documentElement when scrollingElement is not found?

parent = document.scrollingElement || document.documentElement

For jest users, place this in your test setup file:

document.scrollingElement = document.documentElement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

There can be a lot more scrolled than just the window element.
2 participants