For some elements their layout size is important. For instance amp-fit-text picks the right font size given its content and available layout space. In AMP layout size is provided by the framework. However, in Bento, we do not want to depend on heavy framework features and instead need to enable the components themselves to react to size changes.
We can use a relatively new ResizeObserver to monitor size changes. See useResizeObserver as an example. There are some nuances however:
It's near-impossible to polyfill well. ResizeObserver is available in Chrome and Firefox, and will be available in Safari very soon. That still leaves IE and Edge. Partial implementation is possible using window.onresize event, but it's a poor substitution.
For some elements their layout size is important. For instance
amp-fit-text
picks the right font size given its content and available layout space. In AMP layout size is provided by the framework. However, in Bento, we do not want to depend on heavy framework features and instead need to enable the components themselves to react to size changes.We can use a relatively new ResizeObserver to monitor size changes. See useResizeObserver as an example. There are some nuances however:
window.onresize
event, but it's a poor substitution.Very similar reasons should guide "in-viewport" approach with IntersectionObserver.