From 1989a0f04f65a8e12ce2cc1d544fabf2ee96000d Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 9 Sep 2026 10:47:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(mobile):=20=E6=99=AE=E9=80=9APopup=E9=92=B3?= =?UTF-8?q?=E9=AB=98=E5=88=B0=E9=93=BA=E6=BB=A1=E5=8F=AF=E8=A7=86=E5=B1=8F?= =?UTF-8?q?=E6=97=B6=E9=A1=B6=E7=AB=AF=E5=88=87=E5=87=BA=E5=B1=8F=E5=A4=96?= =?UTF-8?q?(=E8=B4=9Ftop=E6=9C=AA=E5=86=99=E5=9B=9E)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实测发现:普通 Popup 高度被 CSS max-height 钳到 ≈window.innerHeight 时, positify_tl 居中标定的负 top(如 -116px)仍留在内联样式里,弹窗顶端被切 到屏外上方。旧 _mobile_clamp 的 `if(t<0) t=0` 只改局部变量没写回元素, 且 `t+h>vh` 判断用置0后的 t 漏掉负 top 场景。 修法:钳制时读内联 top 原值 raw_t——h>=vh 时强制 top=0;否则把 top 钳进 [0, vh-h] 区间;只有 t!=raw_t 才 setProperty important(避免多余写样式)。 --- bricks/popup.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/bricks/popup.js b/bricks/popup.js index 5682628..3f019f1 100644 --- a/bricks/popup.js +++ b/bricks/popup.js @@ -336,12 +336,20 @@ bricks.Popup = class extends bricks.VBox { el.style.setProperty('max-width', vw + 'px', 'important'); } if (!is_win){ + // 普通 Popup 定位钳制:确保整个弹窗落在可视屏内。 + // 高度被钳到≈铺满可视屏时,强制 top=0(否则居中的负 top 会把 + // 顶端切出屏外上方);否则把 top 钳进 [0, vh-h] 区间。 var h = el.offsetHeight; - var t = parseFloat(el.style.top); - if (isNaN(t)) t = 0; - if (t < 0) t = 0; - if (t + h > vh){ - el.style.setProperty('top', Math.max(vh - h, 0) + 'px', 'important'); + var raw_t = parseFloat(el.style.top); + if (isNaN(raw_t)) raw_t = 0; + var t; + if (h >= vh){ + t = 0; + } else { + t = Math.min(Math.max(raw_t, 0), vh - h); + } + if (t !== raw_t){ + el.style.setProperty('top', t + 'px', 'important'); } } }