Skip to content

Commit b4d7b64

Browse files
committed
🚧 Scroll video pane into view after clicking
1 parent e8e46e2 commit b4d7b64

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

‎src/components/VideoCarousel.svelte

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { writable } from 'svelte/store'
88
99
let index = writable(0)
10+
let container: HTMLDivElement
1011
1112
const VIDEOS = [
1213
'fthlphRmsjY', // I Added Mr Beast to Minecraft...
@@ -27,12 +28,16 @@
2728
`//www.youtube.com/oembed?url=https://www.youtube.com/watch?v=${id}&format=json`
2829
)
2930
const videoInfo = await res.json()
30-
3131
return videoInfo?.title
3232
}
33+
34+
function setSelectedVideo(id: string) {
35+
$index = VIDEOS.indexOf(id)
36+
container?.scrollIntoView({ behavior: 'smooth' })
37+
}
3338
</script>
3439

35-
<div class="container">
40+
<div class="container" bind:this={container}>
3641
{#key $index}
3742
<Youtube id={VIDEOS[$index]} animations={false} />
3843
{/key}
@@ -42,8 +47,8 @@
4247
<!-- svelte-ignore a11y-no-static-element-interactions -->
4348
<div
4449
class="thumbnail-container"
45-
on:click={(e) => {
46-
index.set(VIDEOS.indexOf(id))
50+
on:click={() => {
51+
setSelectedVideo(id)
4752
}}
4853
>
4954
<Button class="thumbnail-button">

‎src/routes/+page.svelte

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<script lang="ts">
2-
import Youtube from 'svelte-youtube-embed'
32
import { onDestroy, onMount } from 'svelte'
43
5-
import { Button } from '@svelteness/kit-docs'
4+
// import { Button } from '@svelteness/kit-docs'
65
import { inView } from '$lib'
76
import Carousel from '../components/VideoCarousel.svelte'
7+
// import { fly } from 'svelte/transition'
8+
9+
import MaterialSymbolsClose from '~icons/material-symbols/close'
810
911
let sidebar: HTMLElement | null
1012
let main: HTMLElement | null
@@ -103,9 +105,46 @@
103105
<Carousel></Carousel>
104106
</div>
105107
</div>
108+
109+
<!-- <div class="discord-widget-container">
110+
<Button>
111+
<svelte:component this={MaterialSymbolsClose} />
112+
</Button>
113+
<iframe
114+
class="discord-widget"
115+
title="Discord Widget"
116+
src="https://discord.com/widget?id=785339959518953482&theme=dark"
117+
width="350"
118+
height="350"
119+
allowtransparency="true"
120+
frameborder="200"
121+
sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"
122+
in:fly|global={{ y: 100, duration: 1000, delay: 1000 }}
123+
></iframe>
124+
</div> -->
106125
</div>
107126

108127
<style>
128+
/* :global(.discord-widget-container) {
129+
position: fixed;
130+
bottom: 16px;
131+
right: 16px;
132+
background-color: rgb(88, 101, 242);
133+
border-radius: 16px;
134+
padding-top: 1rem;
135+
}
136+
:global(.discord-widget-container > button) {
137+
position: absolute;
138+
top: 0.25rem;
139+
right: -0.5rem;
140+
}
141+
.discord-widget {
142+
border-radius: 16px;
143+
}
144+
.discord-widget :global(.widgetBody-38iyIo) {
145+
display: none;
146+
} */
147+
109148
.section-title {
110149
display: flex;
111150
flex-direction: column;

0 commit comments

Comments
 (0)