mirror of
https://github.com/tchartron/blow
synced 2024-11-23 12:53:20 +00:00
update
This commit is contained in:
parent
b085644aaa
commit
2bc457fa09
2 changed files with 3 additions and 3 deletions
|
@ -11,8 +11,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
let current_selected_toc = null
|
||||
let current_intersectiong_entry = null
|
||||
const observer = new window.IntersectionObserver(entries => {
|
||||
console.log(entries)
|
||||
entries.forEach(entry => {
|
||||
entries.some(entry => {
|
||||
console.log('observe')
|
||||
// Add 'active' class if observation target is inside viewport
|
||||
// console.log(entry)
|
||||
|
@ -22,6 +21,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
console.log('current', current_intersectiong_entry)
|
||||
if (current_intersectiong_entry !== null && current_intersectiong_entry.isIntersecting) {
|
||||
console.log('should stop')
|
||||
return true
|
||||
}
|
||||
current_intersectiong_entry = entry
|
||||
// console.log(entry, 'active')
|
||||
|
|
|
@ -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=>{console.log(e),e.forEach(n=>{if(console.log("observe"),n.isIntersecting){console.log("entry",n),console.log("current",o),null!==o&&o.isIntersecting&&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.some(n=>{if(console.log("observe"),n.isIntersecting){if(console.log("entry",n),console.log("current",o),null!==o&&o.isIntersecting)return console.log("should stop"),!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)})});
|
Loading…
Reference in a new issue