移动端布局 rem

2018-05-18  本文已影响0人  蘑菇酱960903

window.devicePixelRatio是设备上物理像素和设备独立像素(device-independent pixels (dips))的比例。
公式表示就是:window.devicePixelRatio = 物理像素 / dips
若dpr >
http://www.zhangxinxu.com/wordpress/2012/08/window-devicepixelratio/

(function () {
  var tid
  function recal () {
    var width = document.documentElement.clientWidth
    var rem = 100 * (width / 640)
    document.documentElement.style.fontSize = rem + 'px'
  }
  window.addEventListener('resize', function () {
    clearTimeout(tid)
    tid = setTimeout(recal, 300)
  }, false)
  recal()
})()

上一篇 下一篇

猜你喜欢

热点阅读