Skip to content

Commit a15f3a3

Browse files
Make it autoplay, tidy
1 parent 0b4c539 commit a15f3a3

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

package-lock.json

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@astrojs/svelte": "^6.0.2",
1515
"@astrojs/tailwind": "^5.1.2",
1616
"astro": "^4.16.18",
17+
"embla-carousel-autoplay": "^8.5.1",
1718
"svelte": "^5.2.11",
1819
"tailwindcss": "^3.4.15",
1920
"typescript": "^5.7.2"

src/components/HomepageCarousel.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<script lang="ts">
22
import * as Carousel from "@/components/ui/carousel/index.ts";
33
import { type CarouselAPI } from "@/components/ui/carousel/context.js";
4+
import Autoplay from "embla-carousel-autoplay";
45
import { Button } from "@/components/ui/button";
56
import HomepageCarouselItem from "@/components/HomepageCarouselItem.svelte";
67
interface Props {
8+
speed: number;
79
slides: {
810
image: {
911
path: string;
@@ -15,7 +17,7 @@
1517
actionTo: string;
1618
}[];
1719
}
18-
let { slides }: Props = $props();
20+
let { slides, speed }: Props = $props();
1921
2022
let currentSlide: number = $state(0); // TODO: make check for actual value here. Could break if not starting at 0
2123
@@ -37,6 +39,11 @@
3739
opts={{
3840
loop: true,
3941
}}
42+
plugins={[
43+
Autoplay({
44+
delay: speed,
45+
}),
46+
]}
4047
class="w-full h-fit"
4148
bind:api
4249
>

src/components/HomepageCarouselItem.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
22
import * as Carousel from "@/components/ui/carousel";
3-
import type { Snippet } from "svelte";
43
interface Props {
54
src: string;
65
alt?: string;

src/pages/index.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import HomepageCarousel from '@/components/HomepageCarousel.svelte';
1010
<Navbar/>
1111
</header>
1212
<main class="h-screen">
13-
<HomepageCarousel client:load slides={[
13+
<HomepageCarousel client:load speed={10000} slides={[
1414
{
1515
title:"Lorem Ipsum",
1616
image:{
@@ -21,7 +21,7 @@ import HomepageCarousel from '@/components/HomepageCarousel.svelte';
2121
actionTo:"/"
2222
},
2323
{
24-
title:"2 Lorem Ipsum",
24+
title:"2 Lorem 2 Ipsum",
2525
image:{
2626
path:"/images/IMG_7294.JPG",
2727
},
@@ -30,7 +30,7 @@ import HomepageCarousel from '@/components/HomepageCarousel.svelte';
3030
actionTo:"/"
3131
},
3232
{
33-
title:"3 Lorem Ipsum",
33+
title:"Lorem Ipsum 3: Revenge of the if()",
3434
image:{
3535
path:"/images/IMG_7311.JPG",
3636
},

0 commit comments

Comments
 (0)