Skip to content

Commit 3afd7fa

Browse files
committed
fix: reactive mask width for the orbiting button
1 parent 8e0d26b commit 3afd7fa

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/lib/components/Clock.svelte

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
1717
let interval: any;
1818
19+
let iWidth = $state(window.innerWidth);
20+
function updateWidth() {
21+
iWidth = window.innerWidth;
22+
}
23+
1924
function mapRange(
2025
x: number,
2126
inMin: number,
@@ -48,6 +53,7 @@
4853
}
4954
5055
onMount(() => {
56+
// timer
5157
let hasTemporal: boolean = false;
5258
try {
5359
hasTemporal = Temporal.Now.instant() !== undefined;
@@ -63,10 +69,14 @@
6369
[timeHours, timeMinutes] = getTime(hasTemporal);
6470
updateMarker();
6571
}, 10000);
72+
73+
// HACK: reactive window breakpoints for js
74+
window.addEventListener("resize", updateWidth);
6675
});
6776
6877
onDestroy(() => {
6978
clearInterval(interval);
79+
window.removeEventListener("resize", updateWidth);
7080
});
7181
</script>
7282

@@ -84,9 +94,9 @@
8494
<mask id="orbitMask" mask-type="luminance">
8595
<rect x="0" y="0" width="100" height="100" fill="white" />
8696
<rect
87-
x="45"
97+
x={iWidth >= 768 ? "45" : "35"}
8898
y="0"
89-
width="10"
99+
width={iWidth >= 768 ? "10" : "30"}
90100
height="50"
91101
fill="black"
92102
transform="rotate({angle} 50 50)"

0 commit comments

Comments
 (0)