-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Fix #224 and #857 - toolbar in absolute container #1152
Conversation
positions.top += elementsContainer.scrollTop; | ||
// If container element isn't absolute / fixed, adjust top position according to window scroll position | ||
} else { | ||
positions.top += this.window.pageYOffset; |
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.
Could the calculation of the adjustment of top be done within the if(elementsContainerAboslute)
block above?
Something like:
var topAdjustment = this.window.pageYOffset;
// If container element is absolute / fixed, recalculate boundaries to be relative to the container
if (elementsContainerAbsolute) {
// other existing logic...
topAdjustment = elementsContainer.scrollTop;
}
middleBoundary = boundary.left + boundary.width / 2;
positions.top = (boundary.top - toolbarHeight) + topAdjustment;
That way we can have one less if-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.
Good point. I'll do that
Description
Fix positioning of a toolbar and an anchor preview when
elementsContainer
hasposition: absolute
orposition: fixed
.If
elementsContainer
isabsolute
orfixed
, it will calculate positions relative to this element instead of window.I also added a demo
demo/absolute-container.html
which demonstrates this behavior.