Skip to content

ResizeSensor.js optimization #172

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

Merged
merged 1 commit into from
Jun 9, 2017
Merged

Conversation

FranckFreiburger
Copy link
Contributor

@FranckFreiburger FranckFreiburger commented May 19, 2017

The aim of getComputedStyle(element, 'position') == 'static' is to detect that element is not "positioned".
HTMLElement.offsetParent returns the nearest positioned element in the containment hierarchy.
element.resizeSensor.offsetParent !== element mean that element is not positioned.
(see issue #164)
Right ?

The aim of `getComputedStyle(element, 'position') == 'static'` is to detect that `element` is not "positioned".  
[`HTMLElement.offsetParent`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent) returns the nearest positioned element in the containment hierarchy.  
`element.resizeSensor.offsetParent !== element` mean that  `element` is not positioned.
Right ?
@marcj marcj merged commit 85122fe into marcj:master Jun 9, 2017
@marcj
Copy link
Owner

marcj commented Jun 9, 2017

Very clever, thanks!

@FranckFreiburger FranckFreiburger deleted the patch-1 branch June 9, 2017 18:59
jccr pushed a commit to readium/readium-shared-js that referenced this pull request Sep 15, 2017
…able doc to be "positioned"

The third-party ResizeSensor module wants to set its target element's `position` style to be `relative` as it is key to its functionality.

Unfortunately the condition that checked for this no longer applies to our usage's target element being the 'body'.
It used to check the target element's computed style for position, see if it’s `static` and then change it to `relative`.
As of this patch it no longer does the check in the same way:
marcj/css-element-queries#172

Now it checks the ‘offsetParent’ property of the resize sensor container element, if the offsetParent is not the target element then it applies the ‘relative’ value.
From what I’ve seen by inspecting things with Chrome, looking at the live DOM of the content documents, even if the body has ‘relative’ or not, it by default is the ‘offsetParent’ of the resize sensor element. This means that after this merge the 'position: relative’ that’s needed is no longer applied.
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.

2 participants