From e279ca2c88244e9ade34a68d36dced509078a3f0 Mon Sep 17 00:00:00 2001 From: ThaUnknown <6506529+ThaUnknown@users.noreply.github.com> Date: Tue, 5 Dec 2023 15:09:24 +0100 Subject: [PATCH] fix(web): lazy load trailer --- web/src/lib/components/PreviewCard.svelte | 21 +++++++++++++++++++-- web/src/routes/+page.svelte | 6 +++++- 2 files changed, 24 insertions(+), 3 deletions(-) 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 + } + }