Created
November 22, 2018 04:58
-
-
Save ibreathebsb/482a1dd1ebbe5009f6aa67af857a714f to your computer and use it in GitHub Desktop.
安卓调整系统字体导致rem布局错乱
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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