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) } })
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄
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) } })

更多精彩