mirror of
https://github.com/tchartron/blow
synced 2024-11-27 06:40:31 +00:00
update
This commit is contained in:
parent
8119b2278e
commit
0dc19bb6ad
2 changed files with 4 additions and 4 deletions
|
@ -10,9 +10,9 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
const observer = new window.IntersectionObserver(entries => {
|
||||
entries.forEach(entry => {
|
||||
// Add 'active' class if observation target is inside viewport
|
||||
console.log(entry.isIntersecting)
|
||||
console.log(entry.intersectionRatio)
|
||||
if (entry.intersectionRatio > 0) {
|
||||
// console.log(entry.isIntersecting)
|
||||
// console.log(entry.intersectionRatio)
|
||||
if (entry.isIntersecting) {
|
||||
console.log(entry, 'active')
|
||||
let res = findCorrespondingTocTitle(entry.target)
|
||||
console.log(res)
|
||||
|
|
|
@ -1 +1 @@
|
|||
function activeTocItem(){var e=window.scrollY;console.log(e)}function findCorrespondingTocTitle(o){return[...document.querySelectorAll("#toc li a")].find(e=>e.href.substring(e.href.indexOf("#"))==="#"+o.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);const o=new window.IntersectionObserver(e=>{e.forEach(o=>{if(console.log(o.isIntersecting),console.log(o.intersectionRatio),0<o.intersectionRatio){console.log(o,"active");let e=findCorrespondingTocTitle(o.target);console.log(e),e.classList.add("bg-blue-800")}else console.log(o,"inactive"),o.target.classList.remove("bg-blue-800")})},{root:null,threshold:.1});var t=[];[...e].forEach(e=>{t.push(e.href.substring(e.href.indexOf("#")))});const n=document.querySelectorAll(t.join(","));n.forEach(e=>{o.observe(e)})});
|
||||
function activeTocItem(){var e=window.scrollY;console.log(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);const t=new window.IntersectionObserver(e=>{e.forEach(t=>{if(t.isIntersecting){console.log(t,"active");let e=findCorrespondingTocTitle(t.target);console.log(e),e.classList.add("bg-blue-800")}else console.log(t,"inactive"),t.target.classList.remove("bg-blue-800")})},{root:null,threshold:.1});var o=[];[...e].forEach(e=>{o.push(e.href.substring(e.href.indexOf("#")))});const n=document.querySelectorAll(o.join(","));n.forEach(e=>{t.observe(e)})});
|
Loading…
Reference in a new issue