This commit is contained in:
lzp
2026-03-03 16:16:30 +08:00
parent 30837dfd7e
commit 9817e5e0db
8 changed files with 44 additions and 14 deletions

View File

@@ -2,7 +2,9 @@ import { getUniversalZoomLevel } from '@/utils/tools'
const maxWidth = 1920;
const minWidth = 500;
let flexible = (designWidth = 1920) => {
const maxHeight = 1080;
const minHeight = 500;
let flexible = (designWidth = 1920, designHeight = 1080) => {
var doc = document, win = window, docEl = doc.documentElement, remStyle = document.createElement("style"), tid;
function refreshRem() {
var width = docEl.getBoundingClientRect().width;
@@ -11,7 +13,11 @@ let flexible = (designWidth = 1920) => {
height = getUniversalZoomLevel() * height
if (width > maxWidth) width = maxWidth;
if (width < minWidth) width = minWidth;
var rem = (width * 10 / designWidth).toFixed(2);
if (height > maxHeight) height = maxHeight;
if (height < minHeight) height = minHeight;
const wrem = (width * 10 / designWidth).toFixed(2);
const hrem = (height * 10 / designHeight).toFixed(2);
const rem = Math.min(wrem, hrem);
docEl.style.fontSize = rem + 'px'
}
//要等 wiewport 设置好后才能执行 refreshRem不然 refreshRem 会执行2次