Last active
July 12, 2016 16:02
-
-
Save black-black-cat/363e86c8eecfa20b253a to your computer and use it in GitHub Desktop.
一种计算移动端布局尺寸基准的方法
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(doc, win) { | |
var docEle = doc.documentElement, | |
evt = "onorientationchange" in window ? "orientationchange" : "resize", | |
setBaseFontSize = function() { | |
var width = docEle.clientWidth; | |
// 基于320px宽的设计稿,对应100px的基准字体 | |
width && ( docEle.style.fontSize = 100 / 320 * width + "px" ); | |
}; | |
win.addEventListener(evt, setBaseFontSize, false); | |
doc.addEventListener("DOMContentLoaded", setBaseFontSize, false); | |
}(document, window)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment