解决前端笔记本电脑屏幕显示缩放比例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

相关推荐
liangshanbo121517 分钟前
面试题:前端工程化中 Tree Shaking的原理是什么?
前端·treeshaking
熊猫钓鱼>_>38 分钟前
从闲置平板到家里的“控制大脑“:鸿蒙智慧中控面板完整实战
运维·人工智能·华为·自动化·电脑·ai编程·harmonyos
补码缩写1 小时前
视频跳转触发了seeked,画面就到位了吗
前端
库拉镜像AI牛牛1 小时前
漫剧工作室量产方案:依托知漫剧 AI 短剧降本增效
大数据·服务器·前端·人工智能·语音识别
不可能片场1 小时前
内容运营自动化 用相似度拦住撞车选题
前端·electron
静默回滚1 小时前
视频进度条跳回去,先别改事件监听
前端
Lank_M1 小时前
MP4和WebM导出后为何起播与拖动不同
前端
用户5508492902561 小时前
前端本地存储怎么选:Cookie、localStorage、sessionStorage、IndexedDB 的取舍
前端
用户5508492902561 小时前
Git 日常命令与分支协作流程:从提交到合并的实战梳理
前端
修炼的dance1 小时前
同一段视频没降画质为什么就快了
前端