当前位置: 首页 > news >正文

根据屏幕尺寸设置html根字号fontSize大小并刷新

<script>
// rem等比适配配置文件
// 基准大小
const baseSize = 16
// 设置 rem 函数
function setRem() {// 当前页面宽度相对于 1920宽的缩放比例,可根据自己需要修改。const scale = document.documentElement.clientWidth / 1920console.log(document.documentElement.clientWidth);// 设置页面根节点字体大小(“Math.min(scale, 2)” 指最高放大比例为2,可根据实际业务需求调整)document.documentElement.style.fontSize = (baseSize * Math.min(scale, 2)) + 'px'// 设置fontSize 后就可以使用rem实现适配if (document.documentElement.clientWidth === 3840) {document.documentElement.style.fontSize = '24px'}
}// 初始化
setRem()// 改变窗口大小时重新设置 rem
window.onresize = function () {history.go(0);setRem()
}</script>
<template><div id="app"><!-- <KeepAlive> --><router-view></router-view><!-- </KeepAlive> --></div>
</template><script>
// rem等比适配配置文件
// 基准大小
const baseSize = 16
// 设置 rem 函数
function setRem() {// 当前页面宽度相对于 1920宽的缩放比例,可根据自己需要修改。const scale = document.documentElement.clientWidth / 1920console.log(document.documentElement.clientWidth);// 设置页面根节点字体大小(“Math.min(scale, 2)” 指最高放大比例为2,可根据实际业务需求调整)document.documentElement.style.fontSize = (baseSize * Math.min(scale, 2)) + 'px'if (document.documentElement.clientWidth === 3840) {document.documentElement.style.fontSize = '24px'}
}// 初始化
setRem()// 改变窗口大小时重新设置 rem
window.onresize = function () {history.go(0);setRem()
}export default {name: 'App',components: {}
}
</script><style>
* {margin: 0;padding: 0;
}@font-face {font-family: 'Alibaba PuHuiTi-Bold';src: url('@/assets/fonts/ALIBABA-PUHUITI-BOLD.TTF') format('truetype');font-weight: bold;font-style: normal;
}@font-face {font-family: 'PangMenZhengDao-3';src: url('@/assets/fonts/庞门正道标题体3.0.TTF') format('truetype');font-weight: bold;font-style: normal;
}// 滚动条样式
::-webkit-scrollbar {width: 4px;height: 4px;
}::-webkit-scrollbar-track,
::-webkit-scrollbar-thumb {border-radius: 999px;border: 1px solid transparent;
}::-webkit-scrollbar-track {box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2) inset;
}::-webkit-scrollbar-thumb {min-height: 20px;background-clip: content-box;box-shadow: 0 0 0 5px rgba(0, 0, 0, 0.2) inset;
}::-webkit-scrollbar-corner {background: transparent;
}
</style>
http://www.lryc.cn/news/284051.html

相关文章:

  • Flutter 中的 InteractiveViewer:轻松实现交互性
  • UE4 添加按键输入事件 并在蓝图中使用按键输入节点
  • Go 语言命名规范:清晰、简洁、一致
  • 代码随想录训练营第三十期|第十天|栈与队列part01|理论基础● 232.用栈实现队列● 225. 用队列实现栈
  • Backtrader 文档学习-Indicators混合时间框架
  • 网络攻击与检测防御:维护数字安全的关键挑战
  • 使用 Vector 在 Kubernetes 中收集日志
  • ardupilot开发 --- 固件定制(OEM) 篇
  • 爬虫代理IP在电商行业的应用
  • Vue配置语法检查及关闭语法检查的说明
  • 【Linux】yum
  • 安装sftpgo
  • JS-元素尺寸与位置
  • 2024-01-15(SpringMVCMybatis)
  • Node+Express编写接口---前端
  • 防火墙技术
  • 图灵日记之java奇妙历险记--String类
  • 代码随想录算法训练营第六天| 242 有效的字母异位词 349 两个数组的交集 202 快乐数 1 两数之和
  • 数学建模--比赛
  • JVM工作原理与实战(十六):运行时数据区-Java虚拟机栈
  • DC-4靶机刷题记录
  • 【前端学习笔记1】css基础
  • CVE-2023-46226 Apache iotdb远程代码执行漏洞
  • Redis实战之-分布式锁
  • Cookie同源策略
  • 6、Numpy形状操纵
  • C++初阶类与对象(二):详解构造函数和析构函数
  • 【Vue3】3-3 : 组件之间是如何进行互相通信的
  • 网络端口映射和端口转发的区别和联系
  • VLSI超大规模集成电路设计复习