物理像素自适应布局
分享一个我常用的页面物理像素自适应布局方法:
window.onload = function (){ let dpr = window.devicePixelRatio; let scale = 1/dpr; let width = document.documentElement.clientWidth; let metaNode = document.querySelector('meta[name="viewport"]'); metaNode .setAttribute('content','width=device-width,inital- scale='+scale+',user-scalable'); let htmlNode = document.querySelector('html'); htmlNode.style.fontSize = width * dpr + 'px'; }
window.onload = function (){ let = width = document.documentElement.clientWidth; let htmlNode = document.querySelector('html') ; htmlNode.style.fontSize = width + 'px'; }