Svelte Carousel
Svelte Carousel / Slider
This is a ground-up rewrite of the original Svelte Carousel/Slider using Svelte v3, and Siema, the goal being a fully working carousel with a tiny size.
Usage
This library is pure javascript, so can be used with any framework you like.
Demo
npm run dev # http://localhost:12001
To use within a Svelte application:
npm i -D @beyonk/svelte-carousel
Usage
<Carousel>
<span class="control" slot="left-control">
<ChevronLeftIcon />
</span>
<div class="slide-content">Slide 1</div>
<div class="slide-content">Slide 2</div>
<div class="slide-content">Slide 3</div>
<div class="slide-content">Slide 4</div>
<span class="control" slot="right-control">
<ChevronRightIcon />
</span>
</Carousel>
<script>
import Carousel from './Carousel.svelte'
import { ChevronLeftIcon, ChevronRightIcon } from 'svelte-feather-icons'
</script>
Options
Controls
You can set the controls to be anything you like, though the default height and width are set to 40px. Just use the slots available to insert your own content.
<Carousel>
<span class="control" slot="left-control">
<ChevronLeftIcon />
</span>
<div class="slide-content">Slide 1</div>
...
<div class="slide-content">Slide n</div>
<span class="control" slot="right-control">
<ChevronRightIcon />
</span>
</Carousel>
<script>
import Carousel from './Carousel.svelte'
import { ChevronLeftIcon, ChevronRightIcon } from 'svelte-feather-icons'
</script>
If you need to override height and width, you can use CSS:
.control :global(svg) {
width: 100%;
height: 100%;
color: #fff;
border: 2px solid #fff;
border-radius: 32px;
}
Attributes
You can pass the following attributes:
Attribute | Type | Default Value | Description |
---|
loop | boolean | true | At the end of the carousel, loop through to the first slide again, seamlessly |
perPage | integer | 3 | Number of slides on a single page. Note that this needs to be greater than or equal to the number of slides in your carousel |