2023-08-17 16:46:35 +02:00
|
|
|
<script>
|
2023-07-22 20:44:24 +02:00
|
|
|
import { inview } from 'svelte-inview'
|
2023-08-05 20:33:07 +02:00
|
|
|
import previewRice from '$lib/videos/end_4_rice_intro.mp4'
|
2023-09-10 08:09:06 +02:00
|
|
|
import previewRiceThumbnail from '$lib/videos/end_4_thumbnail.webp'
|
2023-11-13 19:50:05 +01:00
|
|
|
import PlayIcon from '~icons/mingcute/play-circle-line'
|
2023-08-07 19:59:22 +02:00
|
|
|
import clsx from 'clsx'
|
2023-11-14 11:38:18 +01:00
|
|
|
import { onMount } from 'svelte'
|
2023-07-22 20:44:24 +02:00
|
|
|
|
|
|
|
/** @type HTMLVideoElement */
|
|
|
|
let videoElement
|
2023-08-07 19:59:22 +02:00
|
|
|
|
2023-08-17 16:40:51 +02:00
|
|
|
let isVisible = false
|
2023-11-14 11:38:18 +01:00
|
|
|
let isPaused = true
|
2023-08-17 16:45:47 +02:00
|
|
|
|
2023-08-07 19:59:22 +02:00
|
|
|
function togglePlay() {
|
|
|
|
videoElement.paused ? videoElement.play() : videoElement.pause()
|
2023-08-17 16:45:47 +02:00
|
|
|
isPaused = videoElement.paused
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeFullscreen() {
|
|
|
|
videoElement.requestFullscreen()
|
2023-08-07 19:59:22 +02:00
|
|
|
}
|
2023-11-14 11:38:18 +01:00
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
// Nessecary as browsers might block autoplay. The timeout is nessecary as the video is always paused at the very start, even with autoplay on
|
|
|
|
const timeout = setTimeout(() => {
|
|
|
|
isPaused = videoElement.paused
|
|
|
|
}, 10)
|
|
|
|
|
|
|
|
return () => clearTimeout(timeout)
|
|
|
|
})
|
2023-07-22 20:44:24 +02:00
|
|
|
</script>
|
|
|
|
|
2023-09-07 21:03:47 +02:00
|
|
|
<section class={$$restProps.class} class:isVisible>
|
2023-07-22 20:44:24 +02:00
|
|
|
<div
|
2023-09-03 18:00:52 +02:00
|
|
|
class="rice-video"
|
2023-08-07 19:59:22 +02:00
|
|
|
role="banner"
|
2023-09-03 18:00:52 +02:00
|
|
|
use:inview={{ threshold: 0.5 }}
|
2023-08-17 16:40:51 +02:00
|
|
|
on:inview_enter={() => {
|
|
|
|
isVisible = true
|
2023-11-14 11:38:18 +01:00
|
|
|
!isPaused && videoElement.play().catch(() => {})
|
2023-07-22 20:44:24 +02:00
|
|
|
}}
|
2023-08-17 16:40:51 +02:00
|
|
|
on:inview_leave={() => {
|
|
|
|
isVisible = false
|
|
|
|
videoElement.pause()
|
|
|
|
}}
|
2023-08-17 16:45:47 +02:00
|
|
|
on:inview_leave={() => (isVisible = false)}
|
2023-07-22 20:44:24 +02:00
|
|
|
>
|
|
|
|
<video
|
|
|
|
bind:this={videoElement}
|
|
|
|
src={previewRice}
|
|
|
|
disablepictureinpicture="true"
|
|
|
|
disableremoteplayback="true"
|
2023-08-27 17:02:35 +02:00
|
|
|
class="rounded-xl"
|
2023-07-22 20:44:24 +02:00
|
|
|
loop
|
2023-11-14 11:38:18 +01:00
|
|
|
muted
|
2023-07-22 20:44:24 +02:00
|
|
|
preload="auto"
|
2023-11-14 11:38:18 +01:00
|
|
|
autoplay
|
|
|
|
on:play={() => {}}
|
2023-08-05 20:33:07 +02:00
|
|
|
poster={previewRiceThumbnail}
|
2023-08-07 19:59:22 +02:00
|
|
|
on:click={togglePlay}
|
2023-08-17 16:45:47 +02:00
|
|
|
on:dblclick={makeFullscreen}
|
2023-07-22 20:44:24 +02:00
|
|
|
/>
|
2023-08-07 19:59:22 +02:00
|
|
|
<div
|
|
|
|
class={clsx(
|
2023-09-03 18:00:52 +02:00
|
|
|
'z-20 opacity-0 transition-opacity ',
|
2023-09-07 21:03:47 +02:00
|
|
|
isPaused ? 'opacity-100' : 'pointer-events-none'
|
2023-08-07 19:59:22 +02:00
|
|
|
)}
|
|
|
|
>
|
2023-08-17 16:45:47 +02:00
|
|
|
{#if isPaused}
|
|
|
|
<div
|
2023-11-14 11:38:18 +01:00
|
|
|
class="pointer-events-none absolute left-1/2 top-1/2 h-14 w-14 -translate-x-1/2 -translate-y-1/2 rounded-full opacity-80 shadow-sm hover:opacity-100"
|
2023-08-17 16:45:47 +02:00
|
|
|
>
|
2023-11-13 19:50:05 +01:00
|
|
|
<PlayIcon class="h-full w-full" />
|
2023-08-17 16:45:47 +02:00
|
|
|
</div>
|
|
|
|
{/if}
|
2023-08-07 19:59:22 +02:00
|
|
|
</div>
|
2023-08-27 17:02:35 +02:00
|
|
|
|
|
|
|
<a
|
2023-09-03 18:00:52 +02:00
|
|
|
class="absolute -bottom-7 left-0 block max-w-max px-3 pt-2 text-sm font-medium text-slate-100/70 hover:underline"
|
2023-08-27 17:02:35 +02:00
|
|
|
href="https://github.com/end-4/">Setup by @end_4</a
|
|
|
|
>
|
2023-07-22 20:44:24 +02:00
|
|
|
</div>
|
2023-08-27 17:02:35 +02:00
|
|
|
|
2023-09-03 18:00:52 +02:00
|
|
|
<div class="preview-rice-bg" aria="hidden" />
|
2023-07-22 20:44:24 +02:00
|
|
|
</section>
|
|
|
|
|
|
|
|
<style lang="postcss">
|
2023-09-07 21:03:47 +02:00
|
|
|
section {
|
2023-09-10 18:03:08 +02:00
|
|
|
@apply relative z-10 -mb-4 w-full max-w-[1400px] px-1 animate-in fade-in-0 slide-in-from-bottom-10 fill-mode-backwards [animation-delay:1700ms] [animation-duration:2000ms] md:-mt-8 lg:px-8;
|
2023-09-07 21:03:47 +02:00
|
|
|
|
|
|
|
contain: layout style content;
|
|
|
|
}
|
2023-09-03 18:00:52 +02:00
|
|
|
.rice-video {
|
2023-10-28 11:54:13 +02:00
|
|
|
@apply mx-3 rounded-xl;
|
|
|
|
transition: all cubic-bezier(0.9, -1, 0.065, 1.8) 1060ms;
|
2023-09-03 18:00:52 +02:00
|
|
|
position: relative;
|
|
|
|
box-shadow: 0px 0px 44px theme(colors.primary / 80%);
|
|
|
|
border: solid 2px theme(colors.sky.400);
|
|
|
|
scale: 0.9;
|
|
|
|
background: theme(colors.cyan.300 / 70%);
|
2023-11-14 11:38:18 +01:00
|
|
|
aspect-ratio: 16/9;
|
2023-09-03 18:00:52 +02:00
|
|
|
|
|
|
|
& video {
|
2023-10-28 11:54:13 +02:00
|
|
|
transition-property: opacity;
|
|
|
|
transition-duration: inherit;
|
|
|
|
transition-timing-function: inherit;
|
2023-09-03 18:00:52 +02:00
|
|
|
opacity: 0.3;
|
2023-11-14 11:38:18 +01:00
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
2023-09-03 18:00:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.isVisible & {
|
|
|
|
scale: 1;
|
|
|
|
background: transparent;
|
|
|
|
box-shadow: 0px 0px 24px theme(colors.primary / 50%);
|
|
|
|
|
|
|
|
& video {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-22 20:44:24 +02:00
|
|
|
.preview-rice-bg {
|
2023-09-03 18:00:52 +02:00
|
|
|
position: absolute;
|
|
|
|
z-index: -10;
|
2023-09-10 08:09:06 +02:00
|
|
|
pointer-events: none;
|
2023-09-03 18:00:52 +02:00
|
|
|
opacity: 0.4;
|
|
|
|
min-width: 2800px;
|
|
|
|
overflow-x: hidden;
|
|
|
|
top: -160px;
|
|
|
|
left: 50%;
|
|
|
|
translate: -50% 0px;
|
|
|
|
width: 1100px;
|
|
|
|
height: 200%;
|
|
|
|
|
|
|
|
background-image: radial-gradient(
|
|
|
|
closest-side,
|
|
|
|
theme(colors.sky.500),
|
|
|
|
theme(colors.indigo.500 / 0%)
|
|
|
|
);
|
2023-07-22 20:44:24 +02:00
|
|
|
}
|
|
|
|
</style>
|