获取屏幕的PDI值

在设计获取元素的精确样式值第三版的过程中,需要有到PDI值。参考hax的函数,搞出这个:

        var DPI = window.screen.logicalXDPI || (function(){
          var el = document.createElement("div"),s = el.style,
          root = document.documentElement
          s.margin = s.borderWidth = s.padding = '0'
          s.maxWidth = s.minWidth = s.width = '1in'
          root.insertBefore(el,null);
          return  s.pixelWidth || parseInt(window.getComputedStyle(el,null).width)
        })() ;
原文地址:https://www.cnblogs.com/rubylouvre/p/1760510.html