diff --git a/src/js/page.js b/src/js/page.js index 9948fa8..9fc99d4 100644 --- a/src/js/page.js +++ b/src/js/page.js @@ -22,12 +22,12 @@ document.addEventListener("DOMContentLoaded", function() { // console.log('here') if (current_selected_toc !== null) { // console.log(res) - current_selected_toc.classList.remove('bg-blue-800'); + current_selected_toc.parentElement.classList.remove('bg-blue-800'); } current_selected_toc = res } // console.log(res) - res.classList.add('bg-blue-800'); + res.parentElement.classList.add('bg-blue-800'); } else { // has_one_active_toc = false // console.log(entry, 'inactive') diff --git a/static/js/page.js b/static/js/page.js index 59e8e82..5f78c94 100644 --- a/static/js/page.js +++ b/static/js/page.js @@ -1 +1 @@ -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 n=null;const t=new window.IntersectionObserver(e=>{e.forEach(t=>{if(t.isIntersecting){console.log(t,"active");let e=findCorrespondingTocTitle(t.target);void 0===e||null!==n&&n===e||(null!==n&&n.classList.remove("bg-blue-800"),n=e),e.classList.add("bg-blue-800")}})},{root:null,threshold:.1});var o=[];[...e].forEach(e=>{o.push(e.href.substring(e.href.indexOf("#")))});const l=document.querySelectorAll(o.join(","));l.forEach(e=>{t.observe(e)})}); \ No newline at end of file +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 n=null;const t=new window.IntersectionObserver(e=>{e.forEach(t=>{if(t.isIntersecting){console.log(t,"active");let e=findCorrespondingTocTitle(t.target);void 0===e||null!==n&&n===e||(null!==n&&n.parentElement.classList.remove("bg-blue-800"),n=e),e.parentElement.classList.add("bg-blue-800")}})},{root:null,threshold:.1});var o=[];[...e].forEach(e=>{o.push(e.href.substring(e.href.indexOf("#")))});const l=document.querySelectorAll(o.join(","));l.forEach(e=>{t.observe(e)})}); \ No newline at end of file