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)
}
})

猜你喜欢

转载自www.cnblogs.com/ngdty/p/10721625.html
今日推荐