Skip to content

Instantly share code, notes, and snippets.

@ccbikai
Created December 24, 2015 06:27
Show Gist options
  • 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