3 ms·
>Measuring DOM elements and moving them around in JS is quite slow. It is not an inherent property of js-controlled positioning. Browsers don’t have direct me
by wruza 6y ago
>Measuring DOM elements and moving them around in JS is quite slow.
It is not an inherent property of js-controlled positioning. Browsers don’t have direct measuring methods and require stupid workarounds, that’s it. Measuring text layout (most complex thing) in wfh/hfw in js is as fast as in css, because it is just el.getSizeForW(w) and then c++ does the thing as usual. There is no black magic in calculating layouts, it is arithmetic.
>JS layout is also somewhat prone to problems with things like browser zoom level, OS display scaling (although I've not seen that be an issue in a couple of years),
It’s not a property of js either. If a browser provides a stupid internal api that requires manual accounting to zooms and dpi, then css implementation is also prone to that.
>differences between browsers and browser versions, and so on. Layouts with CSS, so long as you're being reasonably conservative, do work quite well in 2020.
The problem is that apps are not conservative, apps want innovation instead of a text layout that spends 20 years to learn a proper vertical alignment.
- Yaggo 6y ago> Browsers don’t have direct measuring methods and require stupid workarounds, that’s it. Oh? There are the old-school e.offset{Top,Right,Bottom,Left} etc methods for measuring the DOM stuff, and there's Visual Viewport API (experimental) for more advanced use cases: https://developer.mozilla.org/en-US/docs/Web/API/Visual_Viewport_API https://developer.mozilla.org/en-US/docs/Web/API/Visual_View...
- wruza 6y agoIt doesn’t work correctly until you root your element into the document under a proper div hierarchy (to simulate all selectors) and wait for it to half-render, and then you remove it, which causes entire document to reflow twice, which is a “stupid workaround” part. With this API you cannot “measure” anything, you can only check what was the result of an already computed and pre-heated flow.
- Yaggo 6y ago> With this API you cannot “measure” anything, you can only check what was the result of an already computed and pre-heated flow. That's a valid point!