-
Notifications
You must be signed in to change notification settings - Fork 18
Polyfill #3
Comments
You do not need anyone's permission, it's an open standard :) The spec is not final yet. I am not sure if we'll end up observing clientWidth or something else, there will be a bug filed about this today. Polyfill is an interesting topic, there is a tension between API correctness, and performance. The obvious polyfill is to do size polling in requestAnimationFrame. The downside is wasted CPU/power. Others have tried to create more performant resize detectors: https://github.com/wnr/element-resize-detector/ is very good, but they all have their quirks. |
Thanks for the response @atotic. As soon as I have time I'll fork and branch this to start playing a little with the standard, even if it's not finished it could arise needs or caveats around the API. Also, as I was reading the spec my first idea was to poll using rAF plus some deboucing since it would stop doing it when the tab is not visible and its polyfill is short to include on top of a project. |
I will add any polyfill attempts here: |
https://github.com/que-etc/resize-observer-polyfill Implements event based tracking of changes in elements dimensions. Uses MutationsObserver and falls back to an infinite dirty checking cycle if the first one is not supported. Handles long running CSS transitions/animations, attributes and nodes mutations along with changes made by :hover pseudo-class (optional). Written in ES6 and compliant with the spec. Doesn't contain any publicly available methods or properties except for those described in the spec. Size is 4.4kb when minified and gzipped. |
https://github.com/ShimShamSam/ResizeListener |
Here is another attempt to watch element resizes. Very simple and straightforward, also small (~350b even not minified). Not a polyfill for this exact spec though. |
@NekR you did not include a link? |
@atotic oh, sorry, silly me. Here it is: https://github.com/developit/simple-element-resize-detector |
I'm using approach from |
Don't observe Content that is on the plane of the display (not zoomed, no Z transform with perspective, no X or Y rotation with perspective) would be fine with We need to be able to react to those changes and (for example) render WebGL content appropriately without visual disparity bugs that would arise from observing values aliased to CSS pixels.
|
@trusktr |
Yes, true. But you've misunderstood. You said:
|
@rjgotten So if you could change that to 👍, that would be nice. :D |
@atotic I think |
@trusktr This is a long thread, unsure what is being asked.
|
@atotic Up above you said
I was simply just saying don't use clientWidth/clientHeight, because those are integers, not floats. Currently the only thing I know of that return floats (as far as polyfills go) is getComputedStyle.
So I guess you maybe thought of that already, but wasn't clear in your previous post about clientWidth which isn't fractional.
What I was saying about transforms is that we need fractional sizing values of element sizes so when transforms are applied we don't see disparity between a transformed element and it's child where the child size is using ResizeObserver to size based on the transformed parent. What would happen is that the size of the parent can appear to change in each animation frame, while the child size (if using clientWidth) would appear to change size only when the parent's rounded size value changed to the nearest integer which may not be every frame. So if you're not planning to use |
@trusktr |
Yeah, we are watching floats. Also, reporting floats. |
I made To work, observer target has to be of
|
Demo: https://jsfiddle.net/c4hmwzaz/7 |
what's the latest status on |
Just turned it on by default in M64. https://bugs.chromium.org/p/chromium/issues/detail?id=612962 |
@atotic nice! so this means it will be in chrome soon? (not behind feature flag) any idea on ff/safari/ie? the use case I'm trying to tackle which it seems like it may work well for is keeping a chat thread scrolled to the bottom **reliably. The current best solution seems to be |
It should be on Dev channel on Nov 14th. |
Chrome'll ship ResizeObserver this month! Just compare Chrome 63 and 64, where the latter has the native implementation. |
I had also made this resize observer which uses an empty iframe and then listens for the resize event of the inner iframe page. Not sure what the performance is. This isn't wrapped as a polyfill yet. Also doesn't work correctly when inside scrollable divs. |
It'll use quite a bit more memory than using an Whether using |
I created a polyfill which aims to be as close as possible to the draft specification.
Feedback is welcomed on this! |
@TremayneChrist Thanks for another one, glad that I do not have to be doing this work. Your approach is to watch for events that might change size (resize, animations, mutations). Will this work for something like el.style.width = "100px"? ResizeObserver spec has moved to CSS Working Group. We've been working on extending the API to allow watching different boxes. The new spec is at https://drafts.csswg.org/resize-observer-1/. We do not have a polyfill for new spec yet. If you have any feedback on the spec, please leave it on https://github.com/w3c/csswg-drafts. |
Hey @atotic,
I looked at the new spec, however, due to the issues/questions around some parts of it, I decided to continue with the older one. On second thoughts, I could add the new box sizes and keep the contentRect, without the deprecation warning for now, as the only other differences seem to be internal. Will have a think and possibly try and get this into the v1 release. |
@atotic I've updated the polyfill so that it can now watch different box sizes. Would be good to get some feedback from everyone, on using this new approach to observing elements. I'm personally not sure about the new property names that are being returned in the entry, but, maybe they will grow on me :) |
In case this goes on I would like to try wirting a polyfill for it, I'm writing this as an issue because I dodn't know how to ask for that chance. Let me know if it's a better way.
The text was updated successfully, but these errors were encountered: