48d6fc1c25
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JJ1g8XV1YhhmHRzhwWEW7o
29 lines
924 B
JavaScript
29 lines
924 B
JavaScript
// 法律/信息页左侧目录滚动高亮
|
|
(function () {
|
|
var toc = document.getElementById('legalToc');
|
|
if (!toc) return;
|
|
var links = Array.prototype.slice.call(toc.querySelectorAll('a'));
|
|
var sections = links
|
|
.map(function (a) { return document.getElementById(a.getAttribute('href').slice(1)); })
|
|
.filter(Boolean);
|
|
if (!sections.length || !window.IntersectionObserver) return;
|
|
|
|
var active = null;
|
|
function setActive(id) {
|
|
if (id === active) return;
|
|
active = id;
|
|
links.forEach(function (a) {
|
|
a.classList.toggle('active', a.getAttribute('href') === '#' + id);
|
|
});
|
|
}
|
|
|
|
var observer = new IntersectionObserver(function (entries) {
|
|
entries.forEach(function (e) {
|
|
if (e.isIntersecting) setActive(e.target.id);
|
|
});
|
|
}, { rootMargin: '-15% 0px -75% 0px', threshold: 0 });
|
|
|
|
sections.forEach(function (s) { observer.observe(s); });
|
|
setActive(sections[0].id);
|
|
})();
|