-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a5dbbf
commit b95830b
Showing
4 changed files
with
80 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<script setup lang="ts"> | ||
defineOptions({ | ||
inheritAttrs: false, | ||
}); | ||
defineProps<{ | ||
path: string; | ||
poster: string; | ||
}>(); | ||
const prefersReducedMotion = import.meta.client | ||
? matchMedia("(prefers-reduced-motion: reduce)").matches | ||
: false; | ||
const video = ref<HTMLVideoElement | undefined>(); | ||
const isPlaying = ref(false); | ||
const hasAutoplay = ref(true); | ||
useIntersectionObserver( | ||
video, | ||
([{ isIntersecting }]) => { | ||
if (isIntersecting && !prefersReducedMotion && hasAutoplay.value) { | ||
video.value?.play(); | ||
isPlaying.value = true; | ||
hasAutoplay.value = false; | ||
} else if (isPlaying.value) { | ||
video.value?.pause(); | ||
isPlaying.value = false; | ||
} | ||
}, | ||
{ threshold: 1 }, | ||
); | ||
function handleVideoClick(event: MouseEvent) { | ||
const player = event.target as HTMLVideoElement; | ||
if (isPlaying.value) { | ||
player.pause(); | ||
isPlaying.value = false; | ||
return; | ||
} | ||
player.play(); | ||
isPlaying.value = true; | ||
} | ||
</script> | ||
|
||
<template> | ||
<div | ||
class="group relative cursor-pointer rounded-xl shadow ring-1 ring-gray-200 dark:ring-gray-800" | ||
:class="[ | ||
!isPlaying && 'hover:ring-primary-500 dark:hover:ring-primary-400', | ||
]" | ||
> | ||
<video | ||
ref="video" | ||
:src="path" | ||
:poster="poster" | ||
muted | ||
class="rounded-xl" | ||
@ended="isPlaying = false" | ||
@click="handleVideoClick" | ||
/> | ||
|
||
<div | ||
v-show="!isPlaying" | ||
class="pointer-events-none absolute inset-0 flex items-center justify-center rounded-xl bg-gradient-to-b from-gray-950/50 to-[rgba(0,0,0,0)] to-20%" | ||
> | ||
<UIcon | ||
name="i-ri-play-circle-fill" | ||
class="group-hover:text-primary-600 h-[4rem] w-[4rem] text-gray-900 md:h-[6rem] md:w-[6rem]" | ||
/> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.