Improve resizing of bounding box

This commit is contained in:
2024-12-09 09:56:41 +01:00
parent f3d94345f6
commit 48e2ad3535
2 changed files with 31 additions and 10 deletions

View File

@@ -13,24 +13,42 @@
{ id: 2, x: 0, y: 0 },
]);
let width = $state(0);
let height = $state(0);
const resize = () => {
width = image?.getBoundingClientRect().width ?? 0;
height = image?.getBoundingClientRect().height ?? 0;
};
onMount(() => {
ws = new WebSocket("/ws");
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
trackers = data;
};
width = image?.getBoundingClientRect().width ?? 0;
height = image?.getBoundingClientRect().height ?? 0;
});
</script>
<svelte:window onresize={resize} />
<div class="relative">
<img src="/scene_drawing.png" alt="" bind:this={image} class="scale-50" />
<img
src="/scene_drawing.png"
alt=""
bind:this={image}
class="scale-50"
onload={resize}
/>
<div
bind:this={parent}
class="absolute inset-0 border border-red-500"
style={"width: " +
image?.getBoundingClientRect().width +
width +
"px; height: " +
image?.getBoundingClientRect().height +
height +
"px;" +
"transform: translate(50%, 50%);"}
>