loit-web-component-gx
Version:
广西时代凌宇前端组件库
23 lines (17 loc) • 1.02 kB
JavaScript
(function(doc, win) {
const docEl = doc.documentElement // 获取html标签
// orientationchange方向改变事件
const resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize'
const recalc = () => { // 当前设备视口宽度
const clientWidth = docEl.clientWidth
console.log('recalc', clientWidth)
if (!clientWidth)
return
// docEl.style.fontSize = 100 * (clientWidth / 1667) + 'px'
docEl.style.fontSize = 100 * (clientWidth / 1920) + 'px'
// docEl.style.fontSize = 100 * (clientWidth / 1366) + 'px'
}
if (!doc.addEventListener) return
win.addEventListener(resizeEvt, recalc, false)
doc.addEventListener('DOMContentLoaded', recalc, false) // load
})(document, window)