From 2becd431852543a0888f21f46fc84d2b4ea5e537 Mon Sep 17 00:00:00 2001 From: Ashley Date: Thu, 17 Aug 2023 12:40:10 +0000 Subject: [PATCH] add IntersectionObserver --- html/poketube.ejs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/html/poketube.ejs b/html/poketube.ejs index 91d214c0..c7bbc311 100644 --- a/html/poketube.ejs +++ b/html/poketube.ejs @@ -1621,6 +1621,21 @@ if (/[?&]autoplay=/.test(location.search)) { } } +const lazyElements = document.querySelectorAll('*'); + +const observer = new IntersectionObserver((entries, observer) => { + entries.forEach(entry => { + if (entry.isIntersecting) { + entry.target.classList.add('loaded'); + observer.unobserve(entry.target); + } + }); +}); + +lazyElements.forEach(element => { + observer.observe(element); +}); + // Function to refresh the page const refreshPage = () => { location.reload();