diff options
Diffstat (limited to 'themes/danix-xyz-hacker/assets/js/article-lazy.js')
| -rw-r--r-- | themes/danix-xyz-hacker/assets/js/article-lazy.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/themes/danix-xyz-hacker/assets/js/article-lazy.js b/themes/danix-xyz-hacker/assets/js/article-lazy.js new file mode 100644 index 0000000..64ca862 --- /dev/null +++ b/themes/danix-xyz-hacker/assets/js/article-lazy.js @@ -0,0 +1,34 @@ +document.addEventListener('DOMContentLoaded', function () { + var timeline = document.querySelector('ol.timeline'); + if (!timeline) return; + + // Progressive enhancement: activates CSS hidden state + timeline.classList.add('js-lazy-timeline'); + + var items = Array.prototype.slice.call( + timeline.querySelectorAll('.timeline-item') + ); + + function reveal(item) { + item.classList.add('is-visible'); + } + + var observer = new IntersectionObserver( + function (entries) { + entries.forEach(function (entry) { + if (entry.isIntersecting) { + reveal(entry.target); + observer.unobserve(entry.target); + } + }); + }, + { + rootMargin: '-80px 0px 0px 0px', + threshold: 0.12, + } + ); + + items.forEach(function (item) { + observer.observe(item); + }); +}); |
