Skip to content

Instantly share code, notes, and snippets.

@black-black-cat
Last active July 12, 2016 16:02
Show Gist options
  • Save black-black-cat/363e86c8eecfa20b253a to your computer and use it in GitHub Desktop.
Save black-black-cat/363e86c8eecfa20b253a to your computer and use it in GitHub Desktop.
一种计算移动端布局尺寸基准的方法
(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