Files

74 lines
1.5 KiB
Vue
Raw Permalink Normal View History

2026-01-25 21:03:44 -05:00
<template>
2026-08-24 15:31:39 -04:00
<div class="stage">
<video
ref="videoEl"
class="video"
src="/caramelldansen.webm"
autoplay
loop
playsinline
preload="auto"
muted
/>
2026-01-27 18:42:35 -05:00
2026-08-24 15:31:39 -04:00
<div class="controls">
<button
class="audio-toggle"
:aria-label="muted ? 'Unmute video' : 'Mute video'"
@click="toggleMute"
>
{{ muted || volume === 0 ? '🔇' : '🔊' }}
</button>
2026-01-27 18:42:35 -05:00
2026-08-24 15:31:39 -04:00
<input
v-model.number="volume"
class="volume"
type="range"
min="0"
max="1"
step="0.01"
aria-label="Volume"
/>
2026-01-25 21:03:44 -05:00
</div>
2026-01-27 18:42:35 -05:00
2026-08-24 15:31:39 -04:00
<div class="brand">gimme.pet</div>
2026-01-25 21:03:44 -05:00
</div>
2026-01-27 18:42:35 -05:00
</template>
<script setup lang="ts">
2026-08-24 15:31:39 -04:00
import { ref, watch, onMounted } from 'vue'
2026-01-27 18:42:35 -05:00
const videoEl = ref<HTMLVideoElement | null>(null)
const muted = ref(true)
2026-08-24 15:31:39 -04:00
const volume = ref(0.8)
2026-01-27 18:42:35 -05:00
2026-08-24 15:31:39 -04:00
// Browsers only allow autoplay while muted, so we start muted and let the
// first user gesture turn the sound on.
function toggleMute() {
2026-01-27 18:42:35 -05:00
muted.value = !muted.value
if (!muted.value) {
2026-08-24 15:31:39 -04:00
if (volume.value === 0) volume.value = 0.8
videoEl.value?.play().catch(() => {})
2026-01-27 18:42:35 -05:00
}
}
2026-08-24 15:31:39 -04:00
watch([muted, volume], ([isMuted, vol]) => {
if (!videoEl.value) return
videoEl.value.muted = isMuted
videoEl.value.volume = vol
})
2026-01-27 18:42:35 -05:00
2026-08-24 15:31:39 -04:00
watch(volume, (vol, prev) => {
if (vol > 0 && prev === 0) muted.value = false
if (vol === 0) muted.value = true
2026-01-27 18:42:35 -05:00
})
2026-08-24 15:31:39 -04:00
onMounted(() => {
if (!videoEl.value) return
videoEl.value.muted = muted.value
videoEl.value.volume = volume.value
videoEl.value.play().catch(() => {})
2026-01-27 18:42:35 -05:00
})
</script>