mirror of
https://github.com/tchartron/blow
synced 2024-11-27 23:00:25 +00:00
update
This commit is contained in:
parent
10202cd194
commit
19e3f32587
2 changed files with 2 additions and 2 deletions
|
@ -15,7 +15,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
console.log(page_titles_elements)
|
console.log(page_titles_elements)
|
||||||
|
|
||||||
let reversed_title_elements = [...page_titles_elements].reverse();
|
let reversed_title_elements = [...page_titles_elements].reverse();
|
||||||
let elem = getActiveTocElement(reversed_title_elements);
|
let elem = getActiveTocElement(reversed_title_elements) || page_titles_elements[0];
|
||||||
console.log(elem)
|
console.log(elem)
|
||||||
findCorrespondingTocTitle(elem).classList.add('bg-blue-800') //page load
|
findCorrespondingTocTitle(elem).classList.add('bg-blue-800') //page load
|
||||||
let previous_elem = elem
|
let previous_elem = elem
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
function getActiveTocElement(e){return[...e].find(e=>e.getBoundingClientRect().y<0)}function findCorrespondingTocTitle(t){return[...document.querySelectorAll("#toc li a")].find(e=>e.href.substring(e.href.indexOf("#"))==="#"+t.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=[];[...e].forEach(e=>{t.push(e.href.substring(e.href.indexOf("#")))});e=document.querySelectorAll(t.join(","));console.log(e);let n=[...e].reverse();e=getActiveTocElement(n);console.log(e),findCorrespondingTocTitle(e).classList.add("bg-blue-800");let o=e;window.addEventListener("scroll",()=>{var e=getActiveTocElement(n);console.log("elem",e),console.log("previous",o),e!==o&&(o.classList.remove("bg-blue-800"),findCorrespondingTocTitle(e).classList.add("bg-blue-800"))})});
|
function getActiveTocElement(e){return[...e].find(e=>e.getBoundingClientRect().y<0)}function findCorrespondingTocTitle(t){return[...document.querySelectorAll("#toc li a")].find(e=>e.href.substring(e.href.indexOf("#"))==="#"+t.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=[];[...e].forEach(e=>{t.push(e.href.substring(e.href.indexOf("#")))});e=document.querySelectorAll(t.join(","));console.log(e);let n=[...e].reverse();e=getActiveTocElement(n)||e[0];console.log(e),findCorrespondingTocTitle(e).classList.add("bg-blue-800");let o=e;window.addEventListener("scroll",()=>{var e=getActiveTocElement(n);console.log("elem",e),console.log("previous",o),e!==o&&(o.classList.remove("bg-blue-800"),findCorrespondingTocTitle(e).classList.add("bg-blue-800"))})});
|
Loading…
Reference in a new issue