This commit is contained in:
Thomas Chartron 2021-11-13 18:48:26 +01:00
parent 9a3ce514b9
commit 0379ccd493
2 changed files with 2 additions and 2 deletions

View file

@ -18,7 +18,7 @@ document.addEventListener("DOMContentLoaded", function() {
let elem = getActiveTocElement(reversed_title_elements) || page_titles_elements[0]; //If no element has gone outside of viewport on y axis
console.log(elem)
findCorrespondingTocTitle(elem).classList.add('bg-blue-800') //page load
let previous_elem = elem
var previous_elem = elem
// table_of_content_links[0].classList.add('bg-blue-800'); //Page load first element selected
window.addEventListener('scroll', () => {
// if (current_active_toc_link === false) { // page load

View file

@ -1 +1 @@
function getActiveTocElement(e){return[...e].find(e=>e.getBoundingClientRect().y<=0)}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 n=[];[...e].forEach(e=>{n.push(e.href.substring(e.href.indexOf("#")))});const t=document.querySelectorAll(n.join(","));console.log(t);let o=[...t].reverse(),l=getActiveTocElement(o)||t[0];console.log(l),findCorrespondingTocTitle(l).classList.add("bg-blue-800");let c=l;window.addEventListener("scroll",()=>{var e=getActiveTocElement(o)||t[0];console.log("element",e),console.log("previous",c),e!==c&&(findCorrespondingTocTitle(c).classList.remove("bg-blue-800"),findCorrespondingTocTitle(e).classList.add("bg-blue-800"),c=l)})});
function getActiveTocElement(e){return[...e].find(e=>e.getBoundingClientRect().y<=0)}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 n=[];[...e].forEach(e=>{n.push(e.href.substring(e.href.indexOf("#")))});const t=document.querySelectorAll(n.join(","));console.log(t);let o=[...t].reverse(),l=getActiveTocElement(o)||t[0];console.log(l),findCorrespondingTocTitle(l).classList.add("bg-blue-800");var c=l;window.addEventListener("scroll",()=>{var e=getActiveTocElement(o)||t[0];console.log("element",e),console.log("previous",c),e!==c&&(findCorrespondingTocTitle(c).classList.remove("bg-blue-800"),findCorrespondingTocTitle(e).classList.add("bg-blue-800"),c=l)})});