解决前端笔记本电脑屏幕显示缩放比例125%、150%对页面大小的影响问题--数据可视化大屏

近期在工作中遇到一个问题,记录一下,在项目上线之后,遇到一个问题,即缩放到90%时,页面字体比默认的100%字体大,一开始毫无头绪,经过一番的Google...Google...Google...,终于找到了解决方法,这是因为大多数笔记本电脑默认的缩放比例为125%或者是150%,所以就出现了在本身台式电脑(默认100%)上开发出来的页面都是按照100%比例来开发的,之后在笔记本电脑上打开缩放比例的时候会出现字体大小显示不合理的问题,这种问题主要是因为device-pixel-ratio导致的

原文链接:https://blog.csdn.net/m0_46318298/article/details/133786669

1.新建一个js文件

复制代码
// detectZoom.js
export const detectZoom = () => {
  let ratio = 0
  const screen = window.screen
  const 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
}
  1. 在入口文件main.js引入

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

题外--数据可视化大屏实现技术方案 vue和react的

vue + v-scale-screen组件 + dataV组件

react + r-scale-screen + dataV

相关推荐
掰头战士5 小时前
聊聊 Function Calling,你的模型是否答非所问?
前端·typescript·agent
Yeyu5 小时前
车载多 App 同屏渲染(三):RemoteCompose 序列化 UI
前端
weixin199701080165 小时前
[特殊字符]《京东POP二手品类对接:B2C订单模型 vs 二手C2C属性的字段转换难题》(附Python源码)
前端·python·算法
三小河6 小时前
AI 对话 "打字机" 是怎么实现的?从 SSE 流式、Markdown 组件到 Nginx 防粘连
前端·人工智能·面试
雪芽蓝域zzs6 小时前
第三十七节:防抖、节流封装(composables 通用函数,搜索框防重复请求)
前端·javascript·vue.js
by组态6 小时前
Ricon组态系统通信配置指南
前端·后端·物联网
可涵不会debug6 小时前
LangChain 文本分割器详解:字符分割、Token 分割、硬约束递归分割实战
java·前端·数据库
掘金挖土6 小时前
前端手摸手跑路之 AI 应用开发(四)
前端
LEE6 小时前
Agent 的控制权,为什么正在回到模型手里?
前端·后端
沃夫上校6 小时前
跨域这件事,其实浏览器在替你挡刀
前端·后端·nginx