From 57a8ac5ab7891bb18e5cbe5057f377e2db12c068 Mon Sep 17 00:00:00 2001 From: Thomas Chartron Date: Sat, 13 Nov 2021 16:01:00 +0100 Subject: [PATCH] update --- src/js/page.js | 2 +- static/js/page.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/page.js b/src/js/page.js index 155421a..33b7dcb 100644 --- a/src/js/page.js +++ b/src/js/page.js @@ -18,7 +18,7 @@ document.addEventListener("DOMContentLoaded", function() { // console.log(entry.intersectionRatio) console.log('entry', entry) console.log('current', current_intersectiong_entry) - if (current_intersectiong_entry !== null && current_intersectiong_entry.isIntersecting === false) { + if (current_intersectiong_entry !== null && current_intersectiong_entry.target === entry.target && entry.isIntersecting === false) { console.log('remove') //Previous entry not intersecting anymore remove class and find the new one let res = findCorrespondingTocTitle(current_intersectiong_entry.target) diff --git a/static/js/page.js b/static/js/page.js index 50f5400..a9c6fd9 100644 --- a/static/js/page.js +++ b/static/js/page.js @@ -1 +1 @@ -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,o=null;const n=new window.IntersectionObserver(e=>{e.some(n=>{if(console.log("observe"),console.log("entry",n),console.log("current",o),null!==o&&!1===o.isIntersecting&&(console.log("remove"),findCorrespondingTocTitle(o.target),t.parentElement.classList.remove("bg-blue-800"),o=null),n.isIntersecting&&null===o){console.log("processing"),null!==o&&0{l.push(e.href.substring(e.href.indexOf("#")))});const r=document.querySelectorAll(l.join(","));r.forEach(e=>{n.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,o=null;const n=new window.IntersectionObserver(e=>{e.some(n=>{if(console.log("observe"),console.log("entry",n),console.log("current",o),null!==o&&o.target===n.target&&!1===n.isIntersecting&&(console.log("remove"),findCorrespondingTocTitle(o.target),t.parentElement.classList.remove("bg-blue-800"),o=null),n.isIntersecting&&null===o){console.log("processing"),null!==o&&0{l.push(e.href.substring(e.href.indexOf("#")))});const r=document.querySelectorAll(l.join(","));r.forEach(e=>{n.observe(e)})}); \ No newline at end of file