Javascript - September 9, 2015
As you probably know if you like using CSS viewport units, the support for them isn’t fantastic.
vmax Isn’t supported in any version of ie or edge.vmin Isn’t supported in ie9vw: 1/100th viewport widthvh: 1/100th viewport heightvmin: 1/100th of the smallest sidevmax: 1/100th of the largest sideNote: IE9 uses vm instead of vmin. It does not support vmax.
var vw = window.innerWidth / 100var vh = window.innerHeight / 100var vmin = Math.min(vw, vh)var vmax = Math.max(vw, vh)html font-size to a viewport unit and using em values everywhere, results in ridiculously responsive web pages/* Can't set the rem value to a viewpoint unit */
.mySelector {
font-size: calc( 2vmin + 1.4vmax + 2vh );
}
The same thing in javascript.
// but with javascript you can!
function setSize() {
var vw = window.innerWidth / 100
var vh = window.innerHeight / 100
var vmin = Math.min(vw, vh)
var vmax = Math.max(vw, vh)
document.documentElement.style.fontSize = (( vmin * 2 ) + ( vmax * 1.4 ) + ( vh * 2 )) + "px";
}
window.addEventListener("resize", setSize);
document.addEventListener("DOMContentLoaded", setSize);