This commit is contained in:
Thomas Chartron 2021-11-13 13:37:00 +01:00
parent 758e63e85d
commit 3e301c0f11
2 changed files with 18 additions and 1 deletions

View file

@ -2,9 +2,26 @@ document.addEventListener("DOMContentLoaded", function() {
// ---------------- TOC Scrollspy --------------------
const navbar_height = document.getElementById('navbar').clientHeight
const table_of_content = document.getElementById('toc')
const page_content = document.getElementById('page-content')
// const navSections = new Array($('.toc').length);
window.addEventListener('scroll', activeTocItem)
const el = document.querySelector('#el')
const observer = new window.IntersectionObserver(([entry]) => {
if (entry.isIntersecting) {
console.log(entry)
console.log('ENTER')
return
}
console.log(entry)
console.log('LEAVE')
}, {
root: null,
threshold: 0.1, // set offset 0.1 means trigger if atleast 10% of element in viewport
})
observer.observe(page_content);
// tocItems.each(function (i) {
// let id = $(this).attr("id").substring(5);
// navSections[i] = document.getElementById(id);

View file

@ -1 +1 @@
function activeTocItem(){var e=window.scrollY;console.log(e)}document.addEventListener("DOMContentLoaded",function(){document.getElementById("navbar").clientHeight,document.getElementById("toc");window.addEventListener("scroll",activeTocItem)});
function activeTocItem(){var e=window.scrollY;console.log(e)}document.addEventListener("DOMContentLoaded",function(){document.getElementById("navbar").clientHeight,document.getElementById("toc");var e=document.getElementById("page-content");window.addEventListener("scroll",activeTocItem);document.querySelector("#el");const o=new window.IntersectionObserver(([e])=>{if(e.isIntersecting)return console.log(e),void console.log("ENTER");console.log(e),console.log("LEAVE")},{root:null,threshold:.1});o.observe(e)});