KcdMp.env.screen
The size of the page and its display’s pixel ratio.
Read it when you need it: every read gives a fresh object with the size at that moment, so a page that adapts to its
size reads it again on a resize event.
Syntax
Section titled “Syntax”KcdMp.env.screenKcdMpScreen
KcdMpScreen
Section titled “KcdMpScreen”The size of the page and of the display it is drawn on.
| Field | Type | |
|---|---|---|
w |
number |
the page’s width in CSS pixels |
h |
number |
the page’s height in CSS pixels |
scale |
number |
the display’s pixel ratio (2 on a display that draws two device pixels per CSS pixel) |
Example
Section titled “Example”window.addEventListener("resize", () => { const { w, h } = KcdMp.env.screen; document.body.classList.toggle("narrow", w < 900 || h < 500);});