How exactly would I pass a javascript variable to a css file in such as that, the css file can use that variable to scale the page dynamically. I have already figured out a hack to do it with a single javascript variable using the REM unit.
var i=128;
while (i--){
document.write("<div id='divtoresize'></div>");
}
var HTML = document.getElementsByTagName('HTML')[0];
(input.onchange = function(){
// changing the font-size of HTML changes the multiplier of the REM unit
HTML.style.fontSize = input.value.toString() + "px";
})();
#divtoresize {
background-color: red;
/* the rem unit is the font-size of HTML */
width: calc(.1rem + 1px);
height: calc(.1rem + 1px);
line-height: 0px;
font-size: 0px;
margin: 0px;
padding: 0px;
display: inline-block;
}
#input {
width: calc(100% - 10px);
position: absolute;
top: 0px;
}
body {
white-space: pre-wrap;
font-size: 1em; /* to prevent changes of HTML from being inherited by the body */
}
<input id="input" type="range" min="0" max="200" value="20" />
This question may seem like an insignificant issue which you can brush off with more javascript, less CSS. However, when the page layouts get big and the number of elements that need to be updated each time the cursor moves grows into the hundreds, javascript (especially if you are using JQuery) becomes less and less practical because of all the lag.
I already know that there are CSS variables which would be perfect for this. However, just glancing at the polyfill for CSS variables in IE makes me cringe so much that I have found mercy for IE in my heart. So, are there any alternatives to CSS variables for this that allow more than one variable to be passed to the CSS?
Also, I am not looking for LESS or any other preprocessors, rather I am looking for pure CSS. Things like LESS use javascript under the skin in a way I am posting this post to avoid.
CLARIFICATION: To clarify, the end goal of this question is to find some way to perform less DOM operations for better performance.
CLARIFICATION #2: Yes, the demo could be coded a lot more efficiently. Thats why its a demo: to demonstrate my problem in a simpler way.