当前位置: 首页> 房产> 建筑 > 常州网站设计_计算机开发工具有哪些_电商运营平台_爱站网关键词挖掘机

常州网站设计_计算机开发工具有哪些_电商运营平台_爱站网关键词挖掘机

时间:2025/9/8 20:33:16来源:https://blog.csdn.net/qq_35556763/article/details/147305967 浏览次数:0次
常州网站设计_计算机开发工具有哪些_电商运营平台_爱站网关键词挖掘机

一、需求:开发都是在缩放100%情况下编码,但是用户的电脑绝大多数是缩放125%,导致页面出现滚动条,字体大小错误,所以需要做适配。

在这里插入图片描述

二、解决思路:可以先获取电脑当前缩放值,再用100除以这个值,得到zoom值,再将全局的body.style.zoom赋值

1.创建detectZoom.js文件

// detectZoom.js
export const detectZoom = () => {let ratio = 0const screen = window.screenconst 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
}

2.在main.js使用这个文件

// 处理笔记本系统默认系统比例为125%或150%带来的布局影响
import { detectZoom } from '@/utils/detectZoom'
const m = detectZoom()
document.body.style.zoom = 100 / Number(m)
console.log(document.body.style.zoom, '当前zoom')

可以看到当前页面显示正常,没有出现滚动条,字体大小也正常
在这里插入图片描述

关键字:常州网站设计_计算机开发工具有哪些_电商运营平台_爱站网关键词挖掘机

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: