zoukankan      html  css  js  c++  java
  • ps切图测量编写的css代码与网页显示不同的问题解决

    参考:https://www.cnblogs.com/LiuWeiLong/p/6058059.html

    今天发现 win10电脑可能存在缩放的情况,出现 切图 120px,css设置120px,但是网页展示 显示为 120*1.25 px 的问题。

    /**
           * 动态更改全局页面缩放,防止切图与显示不同
           */
           window.onresize = function(e){
            detectZoom();
          }
          function detectZoom() {
              var ratio = 0,
                  screen = window.screen,
                  ua = navigator.userAgent.toLowerCase();
    
              if (window.devicePixelRatio !== undefined) {
                  ratio = window.devicePixelRatio;
              }
              else if (~ua.indexOf('msie')) {
                  if (screen.deviceXDPI && screen.logicalXDPI) {
                      ratio = screen.deviceXDPI / screen.logicalXDPI;
                  }
              }
              else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
                  ratio = window.outerWidth / window.innerWidth;
              }
    
              if (ratio) {
                  ratio = Math.round(ratio * 100);
              }
              // return ratio;
              document.querySelector("html").style.fontSize = (16 / (ratio / 100)) + "px";
          }
  • 相关阅读:
    Lambda
    Thread&线程池
    异常
    Map
    List and Set
    Collection和迭代器Iterator
    Object类,常用API
    (一)自定义 mybatis 之框架介绍
    Nginx三大功能及高并发分流
    http协议改为https
  • 原文地址:https://www.cnblogs.com/xiaqiuchu/p/12741869.html
Copyright © 2011-2022 走看看