Skip to content

Instantly share code, notes, and snippets.

@ibreathebsb
Created November 22, 2018 04:58
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 ibreathebsb/482a1dd1ebbe5009f6aa67af857a714f to your computer and use it in GitHub Desktop.
Save ibreathebsb/482a1dd1ebbe5009f6aa67af857a714f to your computer and use it in GitHub Desktop.
安卓调整系统字体导致rem布局错乱
function calcREM() {
var docEl = document.documentElement;
var width = docEl.getBoundingClientRect().width;
var rem = width / 7.5;
rem = parseFloat(rem.toFixed(3));
docEl.style.fontSize = rem + 'px';
// 修正系统字体调整造成的布局问题
var realitySize = parseFloat(window.getComputedStyle(document.documentElement).fontSize);
if (rem !== realitySize) {
rem = rem * rem / realitySize;
docEl.style.fontSize = rem + 'px';
}
window.REM = rem;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment