|
| 1 | +<script setup lang="ts"> |
| 2 | +const video = ref<HTMLVideoElement>() |
| 3 | +const isHovered = ref(false) |
| 4 | +const hasPlayedTeaser = useState('hasPlayedCertificateTeaser', () => false) |
| 5 | +
|
| 6 | +onMounted(() => { |
| 7 | + if (!video.value || hasPlayedTeaser.value) return |
| 8 | + video.value.currentTime = 0 |
| 9 | + hasPlayedTeaser.value = true |
| 10 | + video.value.play() |
| 11 | +
|
| 12 | + setTimeout(() => { |
| 13 | + if (!video.value || isHovered.value) return |
| 14 | + reverseVideoToZero() |
| 15 | + }, 600) |
| 16 | +}) |
| 17 | +
|
| 18 | +// Reverse the video to the beginning with a smooth transition |
| 19 | +let interval |
| 20 | +function reverseVideoToZero() { |
| 21 | + if (!video.value) return |
| 22 | + if (interval) { |
| 23 | + clearInterval(interval) |
| 24 | + interval = null |
| 25 | + } |
| 26 | + if (video.value.currentTime <= 0) return |
| 27 | + video.value.pause() |
| 28 | + interval = setInterval(() => { |
| 29 | + if (isHovered.value) return |
| 30 | + video.value.currentTime = Math.max(0, video.value.currentTime - 0.05) |
| 31 | + if (video.value.currentTime <= 0) { |
| 32 | + clearInterval(interval) |
| 33 | + interval = null |
| 34 | + } |
| 35 | + }, 50) |
| 36 | +} |
| 37 | +
|
| 38 | +const handleMouseEnter = () => { |
| 39 | + isHovered.value = true |
| 40 | + if (!video.value) return |
| 41 | + if (interval) { |
| 42 | + clearInterval(interval) |
| 43 | + interval = null |
| 44 | + } |
| 45 | + video.value.play() |
| 46 | +} |
| 47 | +
|
| 48 | +const handleMouseLeave = () => { |
| 49 | + isHovered.value = false |
| 50 | + if (!video.value) return |
| 51 | + reverseVideoToZero() |
| 52 | +} |
| 53 | +</script> |
| 54 | + |
| 55 | +<template> |
| 56 | + <div class="group relative border border-default rounded-md hover:bg-elevated/50 w-full transition-colors p-2"> |
| 57 | + <ULink |
| 58 | + to="https://certification.nuxt.com" |
| 59 | + target="_blank" |
| 60 | + class="absolute inset-0 z-10" |
| 61 | + @mouseenter="handleMouseEnter" |
| 62 | + @mouseleave="handleMouseLeave" |
| 63 | + /> |
| 64 | + <div class="flex justify-center w-full aspect-video"> |
| 65 | + <video |
| 66 | + ref="video" |
| 67 | + class="w-full rounded-sm" |
| 68 | + poster="https://res.cloudinary.com/nuxt/video/upload/so_0/v1763564406/nuxt-certificate-black-friday-2025_hfskaj.jpg" |
| 69 | + muted |
| 70 | + playsinline |
| 71 | + > |
| 72 | + <source src="https://res.cloudinary.com/nuxt/video/upload/v1763564406/nuxt-certificate-black-friday-2025_hfskaj.mp4" type="video/mp4"> |
| 73 | + </video> |
| 74 | + </div> |
| 75 | + |
| 76 | + <div class="font-bold text-sm text-muted transition-colors group-hover:text-default pt-2"> |
| 77 | + <UBadge color="warning" variant="soft" label="Black Friday Week" /> |
| 78 | + </div> |
| 79 | + |
| 80 | + <div class="text-xs text-muted py-1 transition-colors group-hover:text-default"> |
| 81 | + Get 60% off and bonuses on all Official Nuxt Certifications. |
| 82 | + </div> |
| 83 | + </div> |
| 84 | +</template> |
0 commit comments