I've got a noob question. I have an Element and I ...
# javascript
a
I've got a noob question. I have an Element and I want to attach another element (threejs canvas) to it using element size for the canvas. Then I need to resize canvas when parent element is resized. Simple
element.clientWidth
works with bootstrap columns, but if I have some kind of inner structure,
element.clientWidth
returns zero. As far as I can understand it happens because when I take the measurement, the element is not yet rendered. What is the best way to treat this problem?
r
I'm using https://www.npmjs.com/package/element-resize-event for this. It helps to listen for the resize event, when everything is already rendered.
It took some time experimenting in KVision code, but it allows me to get exactly the result you want - resize canvas when parent element is resized (see how the Paint application works in the Desktop example https://rjaros.github.io/kvision-examples/desktop/)
🔥 1
a
Thanks, I will try it. I just can't get used to the fact, that JS needs library for every simple thing.