blow/static/js/page.js
Thomas Chartron 66e2761736 update
2021-11-13 18:45:52 +01:00

1 line
No EOL
979 B
JavaScript

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