From 2eb0672f7b11d8abf36ed89f3573b94b60ae4349 Mon Sep 17 00:00:00 2001 From: Thomas Chartron Date: Sat, 13 Nov 2021 15:42:19 +0100 Subject: [PATCH] update --- src/js/page.js | 8 ++++++-- static/js/page.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/js/page.js b/src/js/page.js index df6bb38..c1e1657 100644 --- a/src/js/page.js +++ b/src/js/page.js @@ -16,12 +16,16 @@ document.addEventListener("DOMContentLoaded", function() { // Add 'active' class if observation target is inside viewport // console.log(entry) // console.log(entry.intersectionRatio) + if (current_intersectiong_entry === null || current_intersectiong_entry.target.getBoundingClientRect().y < 0) { + console.log('reprocess') + } if (entry.isIntersecting) { + console.log('intersecting') console.log('entry', entry) - console.log('current', current_intersectiong_entry) + // console.log('current', current_intersectiong_entry) if (current_intersectiong_entry !== null) { console.log('current', current_intersectiong_entry.target.getBoundingClientRect().y) - console.log('should stop') + // console.log('should stop') } current_intersectiong_entry = entry // console.log(entry, 'active') diff --git a/static/js/page.js b/static/js/page.js index 56f2326..d4cf11f 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.forEach(n=>{if(console.log("observe"),n.isIntersecting){console.log("entry",n),console.log("current",o),null!==o&&(console.log("current",o.target.getBoundingClientRect().y),console.log("should stop"));let e=findCorrespondingTocTitle((o=n).target);void 0===e||null!==t&&t===e||(null!==t&&t.parentElement.classList.remove("bg-blue-800"),t=e),e.parentElement.classList.add("bg-blue-800")}})},{root:null,threshold:.1});var l=[];[...e].forEach(e=>{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.forEach(n=>{if(console.log("observe"),(null===o||o.target.getBoundingClientRect().y<0)&&console.log("reprocess"),n.isIntersecting){console.log("intersecting"),console.log("entry",n),null!==o&&console.log("current",o.target.getBoundingClientRect().y);let e=findCorrespondingTocTitle((o=n).target);void 0===e||null!==t&&t===e||(null!==t&&t.parentElement.classList.remove("bg-blue-800"),t=e),e.parentElement.classList.add("bg-blue-800")}})},{root:null,threshold:.1});var l=[];[...e].forEach(e=>{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