From 732c6738c4ef4d9dd1ef5ca093b204c5f817dfe4 Mon Sep 17 00:00:00 2001 From: Thomas Chartron Date: Sat, 13 Nov 2021 17:04:33 +0100 Subject: [PATCH] update --- src/js/page.js | 7 ++++--- static/js/page.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/js/page.js b/src/js/page.js index c833121..d3dcc39 100644 --- a/src/js/page.js +++ b/src/js/page.js @@ -16,6 +16,7 @@ document.addEventListener("DOMContentLoaded", function() { // Add 'active' class if observation target is inside viewport // console.log(entry) // console.log(entry.intersectionRatio) + console.log('before') console.log('entry', entry) console.log('current', current_intersectiong_entry) if (current_intersectiong_entry === null && entry.isIntersecting) { @@ -24,9 +25,9 @@ document.addEventListener("DOMContentLoaded", function() { current_intersectiong_entry = entry return true; } - // if (current_intersectiong_entry !== null) { - // return true - // } + console.log('after') + console.log('entry', entry) + console.log('current', current_intersectiong_entry) if (entry.isIntersecting === false) { //some section got out of viewport remove its active class and add to next sibling let res = findCorrespondingTocTitle(entry.target) //First intersection entry res.parentElement.classList.remove('bg-blue-800'); diff --git a/static/js/page.js b/static/js/page.js index 85e4be3..5e4a9f2 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.some(t=>{if(console.log("entry",t),console.log("current",n),null===n&&t.isIntersecting){let e=findCorrespondingTocTitle(t.target);return e.parentElement.classList.add("bg-blue-800"),n=t,!0}if(!1===t.isIntersecting){let e=findCorrespondingTocTitle(t.target);e.parentElement.classList.remove("bg-blue-800"),e.parentElement.nextElementSibling.classList.add("bg-blue-800")}})},{root:null,threshold:.1});var o=[];[...e].forEach(e=>{o.push(e.href.substring(e.href.indexOf("#")))});const r=document.querySelectorAll(o.join(","));r.forEach(e=>{t.observe(e)})}); \ No newline at end of file +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 t=null;const n=new window.IntersectionObserver(e=>{e.some(n=>{if(console.log("before"),console.log("entry",n),console.log("current",t),null===t&&n.isIntersecting){let e=findCorrespondingTocTitle(n.target);return e.parentElement.classList.add("bg-blue-800"),t=n,!0}if(console.log("after"),console.log("entry",n),console.log("current",t),!1===n.isIntersecting){let e=findCorrespondingTocTitle(n.target);e.parentElement.classList.remove("bg-blue-800"),e.parentElement.nextElementSibling.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=>{n.observe(e)})}); \ No newline at end of file