Use correct component to determine device size
This commit is contained in:
parent
a6106ac0e1
commit
5d305bb8e7
|
@ -3,21 +3,25 @@
|
|||
import { onMount } from "svelte"
|
||||
|
||||
let width = window.innerWidth
|
||||
let height = window.innerHeight
|
||||
const tabletBreakpoint = 768
|
||||
const desktopBreakpoint = 1280
|
||||
const resizeObserver = new ResizeObserver(entries => {
|
||||
if (entries?.[0]) {
|
||||
width = entries[0].contentRect?.width
|
||||
height = entries[0].contentRect?.height
|
||||
}
|
||||
})
|
||||
|
||||
$: data = {
|
||||
mobile: width && width < tabletBreakpoint,
|
||||
tablet: width && width >= tabletBreakpoint && width < desktopBreakpoint,
|
||||
width,
|
||||
height,
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
const doc = document.getElementById("device-root")
|
||||
const doc = document.getElementById("app-root")
|
||||
resizeObserver.observe(doc)
|
||||
|
||||
return () => {
|
||||
|
|
Loading…
Reference in New Issue