;(function (win, doc) { 'use strict' // 设计稿宽度 var designWidth = 750 // 屏幕旋转事件:orientationchange // var resizeEvt = 'orientationchange' in win ? 'orientationchange' : 'resize' // 重计算方法 var recalc = function () { var docEl = doc.documentElement // window.orientation 已从Web标准中删除 var orientation if (win.screen.orientation) { orientation = win.screen.orientation.angle } else { orientation = win.orientation } var clientWidth = docEl.clientWidth if (orientation === 0 || orientation === 180) { // 竖屏 portrait clientWidth = docEl.clientWidth } else if (orientation === 90 || orientation === 270 || orientation === -90) { // 横屏 landscape clientWidth = docEl.clientHeight } // 以设计稿宽度为最大限制 // clientWidth = clientWidth > designWidth ? designWidth : clientWidth var fontSize = clientWidth / designWidth * 100 docEl.style.fontSize = fontSize + 'px' } // 绑定事件 // win.addEventListener(resizeEvt, recalc, false) doc.addEventListener('DOMContentLoaded', recalc, false) })(window, document)