Skip to content

Instantly share code, notes, and snippets.

@ijse
Created August 10, 2016 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ijse/10103803f265cd2b5231fe8d5f33bd62 to your computer and use it in GitHub Desktop.
Save ijse/10103803f265cd2b5231fe8d5f33bd62 to your computer and use it in GitHub Desktop.
dynamic set html font-size
(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