// 法律/信息页左侧目录滚动高亮 (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); })();