diff --git a/src/js/page.js b/src/js/page.js index 362a41b..d58c407 100644 --- a/src/js/page.js +++ b/src/js/page.js @@ -32,6 +32,7 @@ document.addEventListener("DOMContentLoaded", function() { if (element !== previous_elem) { findCorrespondingTocTitle(previous_elem).classList.remove('bg-blue-800') findCorrespondingTocTitle(element).classList.add('bg-blue-800') + previous_elem = elem } }) diff --git a/static/js/page.js b/static/js/page.js index f98fe3c..fbcd3e3 100644 --- a/static/js/page.js +++ b/static/js/page.js @@ -1 +1 @@ -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"))})}); \ No newline at end of file +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(),l=getActiveTocElement(o)||t[0];console.log(l),findCorrespondingTocTitle(l).classList.add("bg-blue-800");let c=l;window.addEventListener("scroll",()=>{var e=getActiveTocElement(o)||t[0];console.log("element",e),console.log("previous",c),e!==c&&(findCorrespondingTocTitle(c).classList.remove("bg-blue-800"),findCorrespondingTocTitle(e).classList.add("bg-blue-800"),c=l)})}); \ No newline at end of file