This commit is contained in:
Thomas Chartron 2021-11-13 15:34:31 +01:00
parent 14cb86eaf9
commit e08efb5c11
2 changed files with 8 additions and 8 deletions

View file

@ -16,13 +16,13 @@ document.addEventListener("DOMContentLoaded", function() {
// Add 'active' class if observation target is inside viewport
// console.log(entry)
// console.log(entry.intersectionRatio)
if (entry.isIntersecting) {
console.log('entry', 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')
}
if (entry.isIntersecting && current_intersectiong_entry !== null && current_intersectiong_entry.target.getBoundingClientRect().y < 0) {
// console.log('entry', entry)
// console.log('current', current_intersectiong_entry)
// if (current_intersectiong_entry !== null && current_intersectiong_entry.target.getBoundingClientRect().y < 0) {
// console.log('current', current_intersectiong_entry.target.getBoundingClientRect().y)
// console.log('should stop')
// }
current_intersectiong_entry = entry
// console.log(entry, 'active')
let res = findCorrespondingTocTitle(entry.target)

View file

@ -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)})});
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&&null!==o&&o.target.getBoundingClientRect().y<0){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)})});