mirror of
https://github.com/tchartron/blow
synced 2024-11-23 12:53:20 +00:00
update
This commit is contained in:
parent
1b5f48c755
commit
0dce86b6b9
2 changed files with 3 additions and 52 deletions
|
@ -19,9 +19,9 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
console.log(entry, 'active')
|
||||
let res = findCorrespondingTocTitle(entry.target)
|
||||
if (typeof res !== 'undefined' && (current_selected_toc === null || current_selected_toc !== res)) {
|
||||
console.log('here')
|
||||
// console.log('here')
|
||||
if (current_selected_toc !== null) {
|
||||
console.log(res)
|
||||
// console.log(res)
|
||||
current_selected_toc.classList.remove('bg-blue-800');
|
||||
}
|
||||
current_selected_toc = res
|
||||
|
@ -49,59 +49,10 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
nav_sections_list.forEach((el) => {
|
||||
observer.observe(el);
|
||||
})
|
||||
// console.log(nav_section_ids)
|
||||
|
||||
// observer.observe(page_content);
|
||||
|
||||
// tocItems.each(function (i) {
|
||||
// let id = $(this).attr("id").substring(5);
|
||||
// navSections[i] = document.getElementById(id);
|
||||
// })
|
||||
|
||||
// function isVisible(tocIndex) {
|
||||
// const current = navSections[tocIndex];
|
||||
// const next = tocIndex < tocItems.length - 1 ? navSections[tocIndex + 1] : $("section.section").get(1);
|
||||
|
||||
// const c = current.getBoundingClientRect();
|
||||
// const n = next.getBoundingClientRect();
|
||||
// const h = (window.innerHeight || document.documentElement.clientHeight);
|
||||
|
||||
// return (c.top <= h) && (c.top + (n.top - c.top) - menuBarHeight >= 0);
|
||||
// }
|
||||
|
||||
// function activateIfVisible() {
|
||||
// for (b = true, i = 0; i < tocItems.length; i++) {
|
||||
// if (b && isVisible(i)) {
|
||||
// tocItems[i].classList.add('is-active');
|
||||
// b = false;
|
||||
// } else
|
||||
// tocItems[i].classList.remove('is-active');
|
||||
// }
|
||||
// }
|
||||
|
||||
// var isTicking = null;
|
||||
// window.addEventListener('scroll', () => {
|
||||
// if (!isTicking) {
|
||||
// window.requestAnimationFrame(() => {
|
||||
// activateIfVisible();
|
||||
// isTicking = false;
|
||||
// });
|
||||
// isTicking = true;
|
||||
// }
|
||||
// }, false);
|
||||
});
|
||||
|
||||
function activeTocItem() {
|
||||
let scroll_position = window.scrollY
|
||||
console.log(scroll_position)
|
||||
}
|
||||
|
||||
function findCorrespondingTocTitle(section) {
|
||||
return [...document.querySelectorAll('#toc li a')].find((item) => {
|
||||
// console.log(item)
|
||||
// console.log(`#${section.id}`)
|
||||
// console.log(item.href.substring(item.href.indexOf("#")))
|
||||
return item.href.substring(item.href.indexOf("#")) === `#${section.id}`
|
||||
})
|
||||
// return result
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
function activeTocItem(){var e=window.scrollY;console.log(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");window.addEventListener("scroll",activeTocItem);let o=null;const n=new window.IntersectionObserver(e=>{e.forEach(n=>{if(n.isIntersecting){console.log(n,"active");let e=findCorrespondingTocTitle(n.target);void 0===e||null!==o&&o===e||(console.log("here"),null!==o&&(console.log(e),o.classList.remove("bg-blue-800")),o=e),e.classList.add("bg-blue-800")}})},{root:null,threshold:.1});var t=[];[...e].forEach(e=>{t.push(e.href.substring(e.href.indexOf("#")))});const l=document.querySelectorAll(t.join(","));l.forEach(e=>{n.observe(e)})});
|
||||
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");window.addEventListener("scroll",activeTocItem);let n=null;const t=new window.IntersectionObserver(e=>{e.forEach(t=>{if(t.isIntersecting){console.log(t,"active");let e=findCorrespondingTocTitle(t.target);void 0===e||null!==n&&n===e||(null!==n&&n.classList.remove("bg-blue-800"),n=e),e.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=>{t.observe(e)})});
|
Loading…
Reference in a new issue