mirror of
https://github.com/tchartron/blow
synced 2024-11-23 21:03:16 +00:00
update
This commit is contained in:
parent
80666eef11
commit
57a8ac5ab7
2 changed files with 2 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -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<o.target.getBoundingClientRect().y&&console.log("stop"),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)})});
|
||||
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<o.target.getBoundingClientRect().y&&console.log("stop"),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)})});
|
Loading…
Reference in a new issue