ElementRect

A function that returns the size of an element.

Demo

Usage

With a reference to an element, you can use the ElementRect utility to get the bounding rectangle of the element.

	<script lang="ts">
  import { ElementRect } from "runed";
 
  let el = $state<HTMLElement>();
  const rect = new ElementRect(() => el);
</script>
 
<textarea bind:this={el}></textarea>
 
<p>Width: {rect.width} Height: {rect.height}</p>
<!-- alternatively -->
<pre>{JSON.stringify(rect.current, null, 2)}</pre>	
MIT

© 2024 Svecosystem Team