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"; }
博 主 :夏秋初
地 址 :https://www.cnblogs.com/xiaqiuchu/p/12741869.html
如果对你有帮助,可以点一下 推荐 或者 关注 吗?会让我的分享变得更有动力~
转载时请带上原文链接,谢谢。
地 址 :https://www.cnblogs.com/xiaqiuchu/p/12741869.html
如果对你有帮助,可以点一下 推荐 或者 关注 吗?会让我的分享变得更有动力~
转载时请带上原文链接,谢谢。