blow/static/js/page.js
Thomas Chartron 10202cd194 update
2021-11-13 18:37:43 +01:00

1 line
No EOL
930 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("#")))});e=document.querySelectorAll(t.join(","));console.log(e);let n=[...e].reverse();e=getActiveTocElement(n);console.log(e),findCorrespondingTocTitle(e).classList.add("bg-blue-800");let o=e;window.addEventListener("scroll",()=>{var e=getActiveTocElement(n);console.log("elem",e),console.log("previous",o),e!==o&&(o.classList.remove("bg-blue-800"),findCorrespondingTocTitle(e).classList.add("bg-blue-800"))})});