Skip to content

Instantly share code, notes, and snippets.

@ccbikai
Created December 24, 2015 06:27
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 ccbikai/204a0faf469438799b8f to your computer and use it in GitHub Desktop.
Save ccbikai/204a0faf469438799b8f to your computer and use it in GitHub Desktop.
rem自适应,宽度计算 1rem === 40px ;
(function(doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function() {
var clientWidth = docEl.clientWidth;
if (!clientWidth) {
return
};
if (clientWidth >= 640) {
docEl.style.fontSize = '80px';
} else {
docEl.style.fontSize = 80 * (clientWidth / 640) + 'px';
}
};
if (!doc.addEventListener) {
return;
};
recalc();
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