This commit is contained in:
Thomas Chartron 2021-11-13 18:23:02 +01:00
parent ae12b153c4
commit 5c210ef308
2 changed files with 14 additions and 12 deletions

View file

@ -23,17 +23,7 @@ document.addEventListener("DOMContentLoaded", function() {
}
})
function setActiveToc(elements) {
elements.reverse();
return [...elements].find((item) => {
return (item.getBoundingRect().y < 0)
})
}
function findCorrespondingTocTitle(section) {
return [...document.querySelectorAll('#toc li a')].find((item) => {
return item.href.substring(item.href.indexOf("#")) === `#${section.id}`
})
}
// let has_one_active_toc = false
// let current_selected_toc = null
@ -173,6 +163,18 @@ function findCorrespondingTocTitle(section) {
// observer.observe(el);
// })
});
function setActiveToc(elements) {
elements.reverse();
return [...elements].find((item) => {
return (item.getBoundingRect().y < 0)
})
}
function findCorrespondingTocTitle(section) {
return [...document.querySelectorAll('#toc li a')].find((item) => {
return item.href.substring(item.href.indexOf("#")) === `#${section.id}`
})
}

View file

@ -1 +1 @@
function setActive(e,t){null!==t&&(findCorrespondingTocTitle(t.target),t.parentElement.classList.remove("bg-blue-800"));let n=findCorrespondingTocTitle(e.target);n.parentElement.classList.add("bg-blue-800")}function setNextActive(e){let t=findCorrespondingTocTitle(e.target);console.log(t),t.parentElement.classList.remove("bg-blue-800"),t.parentElement.nextElementSibling.classList.add("bg-blue-800")}function setPreviousActive(e){let t=findCorrespondingTocTitle(e.target);t.parentElement.classList.remove("bg-blue-800"),t.parentElement.previousElementSibling.classList.add("bg-blue-800")}document.addEventListener("DOMContentLoaded",function(){document.getElementById("navbar").clientHeight,document.getElementById("toc");const e=document.querySelectorAll("#toc li a");document.getElementById("page-content");let t=!1,n=[];[...e].forEach(e=>{n.push(e.href.substring(e.href.indexOf("#")))});const l=document.querySelectorAll(n.join(","));console.log(l),window.addEventListener("scroll",()=>{!1===t?(e[0].classList.add("bg-blue-800"),t=e[0]):console.log(setActive(l))})});
function setActiveToc(e){return e.reverse(),[...e].find(e=>e.getBoundingRect().y<0)}function findCorrespondingTocTitle(t){return[...document.querySelectorAll("#toc li a")].find(e=>e.href.substring(e.href.indexOf("#"))==="#"+t.id)}function setActive(e,t){null!==t&&(findCorrespondingTocTitle(t.target),t.parentElement.classList.remove("bg-blue-800"));let n=findCorrespondingTocTitle(e.target);n.parentElement.classList.add("bg-blue-800")}function setNextActive(e){let t=findCorrespondingTocTitle(e.target);console.log(t),t.parentElement.classList.remove("bg-blue-800"),t.parentElement.nextElementSibling.classList.add("bg-blue-800")}function setPreviousActive(e){let t=findCorrespondingTocTitle(e.target);t.parentElement.classList.remove("bg-blue-800"),t.parentElement.previousElementSibling.classList.add("bg-blue-800")}document.addEventListener("DOMContentLoaded",function(){document.getElementById("navbar").clientHeight,document.getElementById("toc");const e=document.querySelectorAll("#toc li a");document.getElementById("page-content");let t=!1,n=[];[...e].forEach(e=>{n.push(e.href.substring(e.href.indexOf("#")))});const o=document.querySelectorAll(n.join(","));console.log(o),window.addEventListener("scroll",()=>{!1===t?(e[0].classList.add("bg-blue-800"),t=e[0]):console.log(setActive(o))})});