From b3ec0d807332b0af55b3fb8d2edea5a283d078b7 Mon Sep 17 00:00:00 2001 From: shaoyongjun Date: Fri, 8 Nov 2024 10:25:30 +0800 Subject: [PATCH] to:sync --- static/js/event/impl/RSizeEventImpl.js | 40 ++++++++++++++------------ static/yanxuelu.html | 2 +- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/static/js/event/impl/RSizeEventImpl.js b/static/js/event/impl/RSizeEventImpl.js index 9604f41..f66621b 100644 --- a/static/js/event/impl/RSizeEventImpl.js +++ b/static/js/event/impl/RSizeEventImpl.js @@ -34,7 +34,13 @@ define(function (require, exports, module) { //set 1rem = curClientW / designWidth (支持响应式) let nowFrontSize = curClientW / designWidth + 'px'; - curDoc.style.fontSize = nowFrontSize; + if (ctx.isTablet || ctx.isMobile || ctx.isIOS || ctx.isAndroid) { + let dpr = getDpr(); + curDoc.style.fontSize = dpr * nowFrontSize; + } else { + curDoc.style.fontSize = nowFrontSize; + } + console.log("curClientW :", curClientW, "designWidth: ", designWidth, "-> ", nowFrontSize); let testDiv = document.getElementById("testDevice"); testDiv.innerText += "\ncurClientW: " + curClientW; @@ -54,21 +60,12 @@ define(function (require, exports, module) { } - - function refreshEditFrontSize() { - const ctx = require("../../common/ctx"); - let curClientW = ctx.getScreenWidth(); - if (!curClientW) { - return - } - //字体尺寸 https://www.shejidaren.com/zihao-daxiao-sheji-bilv.html - //12~72 px 建议最大字体是48px - + function getDpr() { //获取屏幕像素密度 let dpr = window.devicePixelRatio || 1;//当前设置下 物理像素和虚拟像素的比值 if (!dpr) { //devicePixelRatio这个属性是可以获取到设备的dpr - let devicePixelRatio = win?.devicePixelRatio; + let devicePixelRatio = window?.devicePixelRatio; //判断dpr是否为整数 let isRegularDpr = devicePixelRatio.toString().match(/^[1-9]\d*$/g) if (isRegularDpr) { @@ -85,14 +82,21 @@ define(function (require, exports, module) { dpr = 1; } } + return dpr; + } + + function refreshEditFrontSize() { + const ctx = require("../../common/ctx"); + let curClientW = ctx.getScreenWidth(); + if (!curClientW) { + return + } + //字体尺寸 https://www.shejidaren.com/zihao-daxiao-sheji-bilv.html + //12~72 px 建议最大字体是48px + + let dpr = getDpr(); let myEditFrontSize = document.getElementById("myEdit_main"); - // if (document.documentElement.clientWidth <= 720) { - // myEditFrontSize.style.fontSize = (window.myEdit.ctx.editFrontSize + 6) + 'px'; - // } else { - // myEditFrontSize.style.fontSize = window.myEdit.ctx.editFrontSize * dpr + 'px'; - // } - // myEditFrontSize.style.fontSize = window.myEdit.ctx.editFrontSize * dpr + 'px'; if (ctx.isTablet) { myEditFrontSize.style.fontSize = ctx.editFrontSize * dpr + 'px'; } else { diff --git a/static/yanxuelu.html b/static/yanxuelu.html index 81d26b4..db0d8c9 100644 --- a/static/yanxuelu.html +++ b/static/yanxuelu.html @@ -33,7 +33,7 @@
-
+
测试