-
Notifications
You must be signed in to change notification settings - Fork 95
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
Get scroll parent #65
Conversation
src/scroll-timeline-base.js
Outdated
|
||
case 'absolute': | ||
case 'fixed': | ||
return findClosestAncestor(element, isAbsoluteOrFixedElementContainer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This skips step 2:
If the position property is absolute, the containing block is formed by the edge of the padding box of the nearest ancestor element that has a position value other than static (fixed, absolute, relative, or sticky).
tldr; if position absolute, you need to consider the above condition or any fixed container condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/scroll-timeline-base.js
Outdated
|
||
default: | ||
return getScrollParent(node.parentNode); | ||
return getScrollParent(containingBlock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While technically correct, I do prefer looping over recursion as it's slightly more efficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with minor cleanup
src/scroll-timeline-base.js
Outdated
return getScrollParent(containingBlock); | ||
while (true) { | ||
const containingBlock = getContainingBlock(node); | ||
if (!containingBlock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think it's slightly cleaner to move this to the while condition, e.g.:
while (node = getContainingBlock(node)) {
const style = getComputedStyle(node);
switch(style['overflow-x']) {
case 'auto':
case 'scroll':
case 'hidden':
return node;
}
}
return document.scrollingElement;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. Also added missing special case rule for the body element.
src/scroll-timeline-base.js
Outdated
// of the first visible child body is applied instead. | ||
if (node.tagName != "BODY" || | ||
getComputedStyle(document.scrollingElement).overflow != "visible") | ||
return node; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think it would be clearer if you flipped the condition and used this case for the exception (the body element in these special circumstances) to return document.scrollingElement and then left the return below as returning the node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/scroll-timeline-base.js
Outdated
// The UA must apply the overflow from the root element to the viewport; | ||
// however, if the overflow is visible in both axis, then the overflow | ||
// of the first visible child body is applied instead. | ||
if (node.tagName != "BODY" || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we talked about in person, wouldn't checking node == document.body correctly only apply this behavior to the first child?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks Kevin!
Fix calculation the nearest ancestor scroll container.