mirror of
https://github.com/tchartron/blow
synced 2024-11-27 06:40:31 +00:00
update
This commit is contained in:
parent
1af3989b2d
commit
4304812d29
2 changed files with 10 additions and 4 deletions
|
@ -9,15 +9,21 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
|
||||
// let has_one_active_toc = false
|
||||
let current_selected_toc = null
|
||||
let current_intersectiong_entry = null
|
||||
const observer = new window.IntersectionObserver(entries => {
|
||||
entries.forEach(entry => {
|
||||
console.log('observe')
|
||||
// Add 'active' class if observation target is inside viewport
|
||||
// console.log(entry.isIntersecting)
|
||||
// console.log(entry)
|
||||
// console.log(entry.intersectionRatio)
|
||||
if (entry.isIntersecting) {
|
||||
// has_one_active_toc = true
|
||||
console.log(entry, 'active')
|
||||
console.log('entry', entry)
|
||||
console.log('current', current_intersectiong_entry)
|
||||
if (first_intersectiong_section !== null && current_intersectiong_entry.isIntersecting) {
|
||||
console.log('should stop')
|
||||
}
|
||||
current_intersectiong_entry = entry
|
||||
// console.log(entry, 'active')
|
||||
let res = findCorrespondingTocTitle(entry.target)
|
||||
if (typeof res !== 'undefined' && (current_selected_toc === null || current_selected_toc !== res)) {
|
||||
// console.log('here')
|
||||
|
|
|
@ -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;const n=new window.IntersectionObserver(e=>{e.forEach(n=>{if(console.log("observe"),n.isIntersecting){console.log(n,"active");let e=findCorrespondingTocTitle(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 o=[];[...e].forEach(e=>{o.push(e.href.substring(e.href.indexOf("#")))});const l=document.querySelectorAll(o.join(","));l.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){console.log("entry",n),console.log("current",o),null!==first_intersectiong_section&&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)})});
|
Loading…
Reference in a new issue