Skip to content

Commit

Permalink
Merge pull request #866 from AlejandroSuero/feature/fix-background-vi…
Browse files Browse the repository at this point in the history
…deo-playing

fix(#865): `BackgroundVideo.astro` not playing when changing combat
  • Loading branch information
midudev authored May 17, 2024
2 parents 5026e5c + 3c7722d commit 702544f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions src/components/Combates/BackgroundVideo.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@ interface Props {
}
const { id } = Astro.props
const url = `https://cdn.lavelada.dev/${id}-corto.mp4`
---

<div class="fixed left-0 top-0 -z-10 aspect-video h-[100vh] w-screen" id="bg-video">
<video
id="video-player"
autoplay
muted
loop
class="aspect-video size-full overflow-hidden object-cover opacity-0 transition-opacity duration-500"
style="mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 70%, transparent);"
oncanplay="this.classList.add('opacity-70')"
playsinline
src={url}
>
<source type="video/mp4" src={`https://cdn.lavelada.dev/${id}-corto.mp4`} />
<source type="video/mp4" src={url} />
</video>
</div>

<script>
<script is:inline>
import { $ } from "@/lib/dom-selector"

const $bgVideoDiv = $("#bg-video")

const playVideo = () => {
if ($bgVideoDiv) $bgVideoDiv.querySelector("video")?.play()
else document.removeEventListener("astro:page-load", playVideo)
}

document.addEventListener("astro:page-load", playVideo)
$("#video-player").load()
</script>
2 changes: 1 addition & 1 deletion src/pages/combates/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const prerender = true
<Image
width={combatData.titleSize[0]}
height={combatData.titleSize[1]}
transition:name={`title-image-${combat.id}`}
transition:name={`title-image-${combatData.id}`}
loading={index < 2 ? "eager" : "lazy"}
class:list={[
"group-hover:saturate-15 absolute left-1/2 h-auto max-h-[15rem] w-auto -translate-x-1/2 transform-gpu transition-all duration-300 ease-in-out group-hover:scale-75",
Expand Down

0 comments on commit 702544f

Please sign in to comment.