global player pt. 2 fix window errors
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { browser } from "$app/environment";
|
||||||
import { onDestroy, onMount } from "svelte";
|
import { onDestroy, onMount } from "svelte";
|
||||||
import {
|
import {
|
||||||
getSnapshot,
|
getSnapshot,
|
||||||
@@ -41,6 +42,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateIsMobile() {
|
function updateIsMobile() {
|
||||||
|
if (!browser) return;
|
||||||
isMobile = window.matchMedia?.("(max-width: 1023px)")?.matches ?? false;
|
isMobile = window.matchMedia?.("(max-width: 1023px)")?.matches ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +159,9 @@
|
|||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
updateIsMobile();
|
updateIsMobile();
|
||||||
window.addEventListener("resize", updateIsMobile);
|
if (browser) {
|
||||||
|
window.addEventListener("resize", updateIsMobile);
|
||||||
|
}
|
||||||
|
|
||||||
raf = requestAnimationFrame(tickSnapshot);
|
raf = requestAnimationFrame(tickSnapshot);
|
||||||
|
|
||||||
@@ -165,7 +169,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
window.removeEventListener("resize", updateIsMobile);
|
if (browser) {
|
||||||
|
window.removeEventListener("resize", updateIsMobile);
|
||||||
|
}
|
||||||
if (raf) cancelAnimationFrame(raf);
|
if (raf) cancelAnimationFrame(raf);
|
||||||
media.destroy();
|
media.destroy();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user