tools/flexible.js

let rootSize

function computeSize (ratio) {
let baseWidth
const htmlElement = document.documentElement
let dpr = window.devicePixelRatio
const winWidth = htmlElement.getBoundingClientRect().width
/* if (winWidth > 768 && dpr < 3) {
dpr = 3
} */
if (dpr > 2) {
baseWidth = 375 * dpr
} else {
baseWidth = 375 * dpr
}
rootSize = ((winWidth * dpr) / baseWidth) * 100
htmlElement.style.fontSize = rootSize * ratio + 'px'
}

let w = window.innerWidth
let h = window.innerHeight
if (w >= h) {
computeSize(0.5)
} else {
computeSize(1)
}

window.addEventListener('resize', function (e) {
let w = document.documentElement.clientWidth
let wW = screen.width
let wH = screen.height

if (w === wH) {
computeSize(0.5)
} else if (w === wW) {
computeSize(1)
}
})
posted @ 2019-04-17 09:52  ngdty  阅读(121)  评论(0编辑  收藏  举报