-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip to offset parent in getContainer, #12
- Loading branch information
Showing
2 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3a61134
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.
FYI: calling
window.getComputedStyle
is expensive and the properties on theCSSStyleDeclaration
instance returned from it are live, which means each time you pull a property's value from it, you pay an additional performance cost by having to query the DOM's layout and potentially needing a reflow.For each element on which you access the computed style, you should pull those properties you expect to actually use into local variables (or a new object literal saved as a local variable) and then not touch the object again. That way you can prevent expensive layout reflows from having to happen inbetween reads of the style object's properties.
A helper function that encapsulates this behavior can assist. E.g.
3a61134
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.
Thanks for checking. But
getComputedStyle
is only expensive if there are pending changes to the DOM.getContainer()
only reads from the DOM’s layout state, it never writes. All references toCSSStyleDeclaration
s are gone once the script starts setting classes.There is actually a test in tests-functional.js:500 that ensures that not a single reflow/layout happens while the container queries get evaluated.
But I think you are still right in that calling
getComputedStyle
multiple times for the same element in the same method doesn’t make much sense.The helper function is not necessary I think.
3a61134
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.
I opened issue #47 for this topic, so that I don’t forget to fix it :)
3a61134
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.
Ah. Cool. Missed that.
Sorry. :)