每个块级标签都可以对 clientWidthclientHeightoffsetWidth 以及 offsetHeight 属性进行绑定:

<div bind:clientWidth={w} bind:clientHeight={h}>
	<span style="font-size: {size}px">{text}</span>
</div>

这些绑定是只读的,更改wh 的值不会有任何效果。

对标签的尺寸更改请阅读这里。 由于涉及到额外的性能开销,因此不建议在页面中大量的使用。

使用display: inline的标签无法获得尺寸,当然包含有其他有尺寸的标签 (例如<canvas>)也不会得到正常显示。在这种情况下建议对该标签嵌套一层标签或者直接绑定它的父级。



		
loading editor...

Console

loading Svelte compiler...


		
loading editor...

Compiler options

result = svelte.compile(source, {
generate:
});


		
loading editor...