Skip to content

Instantly share code, notes, and snippets.

@ijse
Created August 10, 2016 07:15
Show Gist options
  • 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