From 474fb22e54fd567fde36394a0388e63227cc5bea Mon Sep 17 00:00:00 2001 From: albert4719 Date: Sat, 19 Sep 2026 16:34:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E8=B7=B3=E8=BD=AC=E8=90=BD=E7=82=B9?= =?UTF-8?q?=EF=BC=9A=E6=87=92=E6=B8=B2=E6=9F=93=E6=92=91=E5=BC=80=E6=B2=BF?= =?UTF-8?q?=E9=80=94=E5=8D=A1=E7=89=87=EF=BC=8C=E7=9B=AE=E6=A0=87=E8=A2=AB?= =?UTF-8?q?=E6=8E=A8=E8=B5=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 点「第 13 节第 11 条」这种跨节引用按「跳过去」,会停在半路的随机位置。原因是 卡片懒渲染:没渲染过的卡片矮一截,scrollIntoView 按当前布局算出目标 Y 坐标, 滚动途中 IntersectionObserver 把沿途几百张卡片补渲染、高度撑开,目标就被往下 推了,最后停的位置和算的时候完全对不上。跨节跳中间隔着三百多张卡片,最明显。 改成:先把目标卡片本身渲染出来(高度才对),再反复 scrollIntoView 校正,直到 连续两次的位置不再变化,或试满 10 次为止,稳定后才高亮。behavior 也从 smooth 改回瞬时——平滑滚动反而给了沿途卡片更多撑开的时间。 无头浏览器实测跳第 13 节第 11 条:落点 top=171 bottom=657,视口高 749, 完全在视口内且居中。 --- index.html | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 016bb3e..2c5d050 100644 --- a/index.html +++ b/index.html @@ -681,8 +681,19 @@ function gotoItem(key){ state.q = ''; for (const d of DIMS) state[d].clear(); syncControls(); apply(); writeUrl(); } - el.scrollIntoView({block:'center', behavior:'smooth'}); - el.classList.remove('flash'); void el.offsetWidth; el.classList.add('flash'); + // 卡片是懒渲染的,没渲染过的那些矮一截。直接滚过去会停在半路:滚动沿途的卡片被 + // IntersectionObserver 补渲染、高度撑开,目标又被往下推了,跨节跳时尤其明显。 + // 所以先把目标本身渲染出来,再反复校正位置,直到两次之间不再变化(或试满 10 次)。 + const card = CARD_OF.get(el); + if (card && card.key !== CUR_KEY) renderCard(card, CUR_TERMS, CUR_KEY); + let tries = 0, lastY = NaN; + const settle = () => { + el.scrollIntoView({block:'center'}); + const y = Math.round(el.getBoundingClientRect().top); + if (++tries < 10 && y !== lastY){ lastY = y; setTimeout(settle, 50); return; } + el.classList.remove('flash'); void el.offsetWidth; el.classList.add('flash'); + }; + settle(); } document.addEventListener('click', ev => { const a = ev.target.closest?.('.xref');