Created
August 10, 2016 07:15
-
-
Save ijse/10103803f265cd2b5231fe8d5f33bd62 to your computer and use it in GitHub Desktop.
dynamic set html font-size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (doc, win) { | |
var docEl = doc.documentElement, | |
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', | |
recalc = function () { | |
var clientWidth = docEl.clientWidth; | |
if (!clientWidth) return; | |
docEl.style.fontSize = 36 * (clientWidth / 320) + 'px'; | |
}; | |
if (!doc.addEventListener) return; | |
win.addEventListener(resizeEvt, recalc, false); | |
doc.addEventListener('DOMContentLoaded', recalc, false); | |
})(document, window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment