diff --git a/web/src/lib/components/PreviewCard.svelte b/web/src/lib/components/PreviewCard.svelte index b34d389..f398093 100644 --- a/web/src/lib/components/PreviewCard.svelte +++ b/web/src/lib/components/PreviewCard.svelte @@ -31,20 +31,37 @@ function play () { open('miru://anime/' + media.id) } + function lazyload (video) { + if ('IntersectionObserver' in window) { + const lazyVideoObserver = new IntersectionObserver(entries => { + for (const { target, isIntersecting } of entries) { + if (isIntersecting) { + video.src = video.dataset.src + lazyVideoObserver.unobserve(target) + } + } + }) + lazyVideoObserver.observe(video.parentNode) + } else { + video.src = video.dataset.src + } + }