diff --git a/src/js/page.js b/src/js/page.js index ed24540..a57d492 100644 --- a/src/js/page.js +++ b/src/js/page.js @@ -10,9 +10,9 @@ document.addEventListener("DOMContentLoaded", function() { const observer = new window.IntersectionObserver(entries => { entries.forEach(entry => { // Add 'active' class if observation target is inside viewport - console.log(entry.isIntersecting) - console.log(entry.intersectionRatio) - if (entry.intersectionRatio > 0) { + // console.log(entry.isIntersecting) + // console.log(entry.intersectionRatio) + if (entry.isIntersecting) { console.log(entry, 'active') let res = findCorrespondingTocTitle(entry.target) console.log(res) diff --git a/static/js/page.js b/static/js/page.js index dd661ef..eca5c2c 100644 --- a/static/js/page.js +++ b/static/js/page.js @@ -1 +1 @@ -function activeTocItem(){var e=window.scrollY;console.log(e)}function findCorrespondingTocTitle(o){return[...document.querySelectorAll("#toc li a")].find(e=>e.href.substring(e.href.indexOf("#"))==="#"+o.id)}document.addEventListener("DOMContentLoaded",function(){document.getElementById("navbar").clientHeight,document.getElementById("toc");var e=document.querySelectorAll("#toc li a");document.getElementById("page-content");window.addEventListener("scroll",activeTocItem);const o=new window.IntersectionObserver(e=>{e.forEach(o=>{if(console.log(o.isIntersecting),console.log(o.intersectionRatio),0{t.push(e.href.substring(e.href.indexOf("#")))});const n=document.querySelectorAll(t.join(","));n.forEach(e=>{o.observe(e)})}); \ No newline at end of file +function activeTocItem(){var e=window.scrollY;console.log(e)}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");window.addEventListener("scroll",activeTocItem);const t=new window.IntersectionObserver(e=>{e.forEach(t=>{if(t.isIntersecting){console.log(t,"active");let e=findCorrespondingTocTitle(t.target);console.log(e),e.classList.add("bg-blue-800")}else console.log(t,"inactive"),t.target.classList.remove("bg-blue-800")})},{root:null,threshold:.1});var o=[];[...e].forEach(e=>{o.push(e.href.substring(e.href.indexOf("#")))});const n=document.querySelectorAll(o.join(","));n.forEach(e=>{t.observe(e)})}); \ No newline at end of file