blow/static/js/page.js
Thomas Chartron eb7d7be213 update
2021-11-13 18:59:20 +01:00

1 line
No EOL
902 B
JavaScript

function getActiveTocElement(e){return[...e].find(e=>e.getBoundingClientRect().y<=0)}function findCorrespondingTocTitle(t){return[...document.querySelectorAll("#toc li a")].find(e=>e.href.substring(e.href.indexOf("#"))==="#"+t.id)}document.addEventListener("DOMContentLoaded",function(){document.getElementById("navbar").clientHeight,document.getElementById("toc");var e=document.querySelectorAll("#toc li a");document.getElementById("page-content");let t=[];[...e].forEach(e=>{t.push(e.href.substring(e.href.indexOf("#")))});const n=document.querySelectorAll(t.join(","));let o=[...n].reverse();e=getActiveTocElement(o)||n[0];findCorrespondingTocTitle(e).classList.add("bg-blue-700");var i=e;window.addEventListener("scroll",()=>{var e=getActiveTocElement(o)||n[0];e!==i&&(findCorrespondingTocTitle(i).classList.remove("bg-blue-700"),findCorrespondingTocTitle(e).classList.add("bg-blue-700"),i=e)})});