It's currently possible to get or set CSS variables from Javascript using either:
// get
getComputedStyle(document.documentElement)
.getPropertyValue('--variable');
// set
document.documentElement.style
.setProperty('--variable', '500px');
But in CSS I can set the style to be this:
:root {
--variable: "1000px";
}
@media( max-width: 800px ) {
:root {
--variable: "400px";
}
}
But the JS won't re-trigger if it is only run on the first load.
Is there any way to make it trigger on events that the CSS would change the value?
Unless the page loaded in < 800px
width, it would get the variable value as 1000px