From bc149af3a02e721f0e3d03a673a0ec64fca765c4 Mon Sep 17 00:00:00 2001 From: albert4719 Date: Mon, 5 Oct 2026 10:07:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E7=B4=A2=E9=A1=B5=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E9=AB=98=E4=BA=AE=E6=94=B9=E6=88=90=E5=8F=AA=E7=9C=8B=E6=A0=87?= =?UTF-8?q?=E9=A2=98=EF=BC=9A=E4=BB=8E=E4=B8=8A=E5=BE=80=E4=B8=8B=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E6=B2=A1=E8=A2=AB=E9=A1=B6=E6=A0=8F=E6=8C=A1?= =?UTF-8?q?=E4=BD=8F=E7=9A=84=E6=9D=A1=E7=9B=AE=E6=A0=87=E9=A2=98=E5=B0=B1?= =?UTF-8?q?=E6=98=AF=E6=AD=A3=E5=9C=A8=E8=AF=BB=E7=9A=84=EF=BC=8C=E8=8A=82?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E7=AE=97=E8=AF=A5=E8=8A=82=E7=AC=AC=201=20?= =?UTF-8?q?=E6=9D=A1=EF=BC=9B=E5=B1=8F=E5=B9=95=E9=87=8C=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E6=97=B6=E5=8F=96=E6=A0=87=E9=A2=98=E5=B7=B2?= =?UTF-8?q?=E6=BB=9A=E8=BF=87=E9=A1=B6=E6=A0=8F=E7=9A=84=E6=9C=80=E5=90=8E?= =?UTF-8?q?=E4=B8=80=E6=9D=A1=E3=80=82=E5=8E=9F=E6=9D=A5=E6=8C=89=E8=A7=86?= =?UTF-8?q?=E5=8F=A3=E4=B8=89=E6=88=90=E5=A4=84=E7=9A=84=E7=BA=BF=E5=88=A4?= =?UTF-8?q?=EF=BC=8C=E4=B8=8A=E4=B8=80=E6=9D=A1=E6=8E=A8=E4=B8=8A=E5=8E=BB?= =?UTF-8?q?=E4=B8=80=E5=8D=8A=E8=BF=98=E5=8E=8B=E7=9D=80=E7=BA=BF=EF=BC=8C?= =?UTF-8?q?=E4=BE=A7=E8=BE=B9=E6=A0=8F=E4=B8=8D=E5=88=87=E3=80=82=E9=95=BF?= =?UTF-8?q?=E6=96=87=E5=BC=B9=E7=AA=97=E7=9B=AE=E5=BD=95=E7=9A=84=E5=88=A4?= =?UTF-8?q?=E5=AE=9A=E7=BA=BF=E4=BB=8E=E9=A1=B6=E9=83=A8=2090px=20?= =?UTF-8?q?=E6=94=B9=E6=88=90=E8=A7=86=E5=8F=A3=E4=B8=8A=E9=83=A8=E4=B8=89?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index cfe28be..36accfc 100644 --- a/index.html +++ b/index.html @@ -814,7 +814,7 @@ function spy(){ clearTimeout(spyT); spyT = setTimeout(() => { const line = innerHeight * 0.3; // 判定线取视口偏上三成,和人读的位置差不多 - let hit = '', near = Infinity; + let hit = ''; // 还在页首读导读和筛选器时,没有「正在看的那一条」,地址栏就该是干净的。 // 否则停在最上面也会被记成 #e-1-1,一刷新就滚到第 1 节标题、导读全没了 // (2026-09-20 用户提的)。判据是第一个节块的顶还在判定线以下。 @@ -825,15 +825,28 @@ function spy(){ history.replaceState(history.state, '', location.pathname + location.search); return; } + // 看标题:从上往下第一个没被顶栏挡住的标题,就是正在读的那条。一屏只放得下一条半, + // 按「压着视口三成处那条线」「露出得多」「中线还在屏幕里」三种判法都试过,都有被用户 + // 抓到的情况(2026-10-05),最后按用户的提议只看标题。节标题算作这一节第 1 条的标题, + // 不然读节首引言和导览时会挑到上一节最后一条。屏幕里一个标题都没有(一条比一屏还高), + // 就取标题已经滚到顶栏上面的最后一条,也就是正在读的这条。 + const top = Math.max(0, document.querySelector('header.nav').getBoundingClientRect().bottom); + const heads = []; // [标题上沿, 落到哪条] + for (const b of BLOCKS){ + const r = b.el.getBoundingClientRect(); + if (!r.height) continue; + const first = CARDS.find(c => c.el.closest('.sec-block') === b.el && c.el.getBoundingClientRect().height); + if (first) heads.push([r.top, first.el.id]); + } for (const c of CARDS){ // 不看 card.vis:那是 CARD_IO 维护的渲染标记,滞后于滚动。直接量一次位置, // 高度为 0 的就是被筛选藏起来的,顺带一并跳过。 - const r = c.el.getBoundingClientRect(); - if (!r.height || r.bottom <= 0 || r.top >= innerHeight) continue; - if (r.top <= line && r.bottom > line){ hit = c.el.id; break; } // 跨过判定线的优先 - const d = Math.abs(r.top - line); - if (d < near){ near = d; hit = c.el.id; } + if (!c.el.getBoundingClientRect().height) continue; + heads.push([c.el.querySelector('.card-h').getBoundingClientRect().top, c.el.id]); } + heads.sort((x, y) => x[0] - y[0]); + hit = heads.find(([t]) => t >= top && t < innerHeight)?.[1] + || heads.filter(([t]) => t < top).pop()?.[1] || ''; if (hit === spyLast) return; spyLast = hit; tocSync(hit); history.replaceState(history.state, '', location.pathname + location.search + (hit ? '#' + hit : '')); @@ -1326,7 +1339,8 @@ function dmTopOf(el){ return el.getBoundingClientRect().top - DM.doc.getBoundingClientRect().top + DM.doc.scrollTop; } function dmSpy(){ - const top = DM.doc.scrollTop + 90; let cur = DM.heads[0]; + // 判定线和主页的 spy 一样取视口偏上三成。原来是顶部 90px,下一节已经占了大半屏,目录还亮着上一节 + const top = DM.doc.scrollTop + Math.max(90, DM.doc.clientHeight * 0.3); let cur = DM.heads[0]; for (const h of DM.heads){ const el = document.getElementById(h.id); if (el && dmTopOf(el) <= top) cur = h; } for (const a of DM.toc.children) a.classList.toggle('on', !!cur && a.dataset.id === cur.id); }