Trying to use Window.innerWidth and load the received value into a CSS variable, but it does not seem to work. What am I doing wrong?
function myFunction() {
var w = window.innerWidth;
document
.documentElement
.style
.setProperty('--window', w);
}
:root {
--window:0px;
}
div {
height: calc(var(--window) / 2);
background: red;
}
<div></div>