• This repository has been archived on 05/May/2022
  • Stars
    star
    213
  • Rank 185,410 (Top 4 %)
  • Language Svelte
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A super lightweight, super simple Carousel for Svelte 3

This project is now archived. We don't use carousels any more, and you shouldn't either.

Svelte Carousel

js-standard-style CircleCI svelte-v2 svelte-v3

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

The simplest possible demo

npm install
npm run dev # http://localhost:12001

To use within a Svelte application:

npm i -D @beyonk/svelte-carousel

Usage

<Carousel>
  <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>
</Carousel>

<script>
	import Carousel from '@beyonk/svelte-carousel'
	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.

npm i -D svelte-feather-icons
<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 less than or equal to the number of slides in your carousel
autoplay integer 0 Auto-change slide at an interval (in milliseconds). 0 means don't autoplay.
duration number 200 Slide transition duration in milliseconds.
easing string 'ease-out' It is like a CSS transition-timing-function β€” describes acceleration curve.
startIndex number 0 Index (zero-based) of the starting slide.
draggable boolean true Use dragging and touch swiping.
multipleDrag boolean true Allow dragging to move multiple slides.
dots boolean true Toggles visibility of slider dots.
controls boolean true Toggles visibility of slider controls. dots.
threshold number 20 Touch and mouse dragging threshold (in px).
rtl boolean false Enables layout for languages written from right to left (like Hebrew or Arabic).

perPage can also be set to a responsive object, to change the number of slides based on screen width:

<Carousel perPage={{ 800: 3, 500: 2 }}>
// will show 1 slide below 500px width, 2 at 500, 3 at 800.

Events

The Carousel components emits the following events:

Name Data Description
change { currentSlide, slideCount } currentSlide: The current slide index. Can be a positive or negative integer. slideCount: The number of slides.

Actions

You can call left, right, go(slideNumber), pause and resume functions on the slider. For example, for pausing the autoslide while the mouse is hover the carousel

<Carousel bind:this={carousel} on:mouseenter={enter} on:mouseleave={leave}>
<div class="slide-content">Slide 1</div>
...
<div class="slide-content">Slide n</div>
</Carousel>

<script>
import Carousel from './Carousel.svelte'
let carousel;

function enter() {
  carousel.pause();
}

function leave() {
  carousel.resume();
}
</script>

More Repositories

1

svelte-mapbox

MapBox Map and Autocomplete components for Svelte (or Vanilla JS)
Svelte
342
star
2

svelte-notifications

Svelte toast notifications component that can be used in any JS application
Svelte
309
star
3

gdpr-cookie-consent-banner

A GDPR compliant cookie consent banner implementation
Svelte
250
star
4

svelte-social-auth

Social Auth for Svelte v3
Svelte
169
star
5

svelte-datepicker

A lightweight datepicker written in Svelte
Svelte
141
star
6

sapper-rbac

RBAC for Sapper
JavaScript
81
star
7

svelte-googlemaps

Svelte Google Maps Components
Svelte
79
star
8

svelte-google-analytics

Google Analytics component for Svelte
JavaScript
77
star
9

http

An isomorphic http client for Svelte applications
JavaScript
45
star
10

svelte-scrollspy

Scroll Spy component for Svelte
JavaScript
38
star
11

now-sapper-demo

Now v2 (Serverless) Sapper Application
JavaScript
23
star
12

svelte-facebook-pixel

A facebook pixel module for Svelte / SvelteKit
Svelte
22
star
13

svelte-toggle

Toggle component for Svelte
Svelte
22
star
14

async-script-loader

Asynchronous script loading for SPAs
JavaScript
17
star
15

svelte-steps

Progress Steps component for Svelte
Svelte
17
star
16

svelte-component-livereload-template

Svelte component template with LiveReload and Jest unit testing
JavaScript
14
star
17

svelte-simple-icons

Simple Brand Icons for Svelte
JavaScript
13
star
18

svelte-tag-input

A super simple, extremely lightweight tag input for Svelte and Vanilla JS
CSS
8
star
19

reorient

Transforms json from one format into another
JavaScript
7
star
20

now-v2-ghost

Experiment trying to get ghost to run on now's v2 platform
CSS
7
star
21

svelte-facebook-customer-chat

Facebook Messaging Platform - Customer Chat Integration
HTML
6
star
22

svelte-scheduler

Scheduling and Calendaring component for Svelte
JavaScript
5
star
23

svelte-trustpilot

Svelte / Vanilla JS Trustpilot Widget with proper SPA support
Svelte
4
star
24

pino-logtail

Pino Logtail log transport
JavaScript
3
star
25

svelte-slim-select

A thin svelte wrapper around slim-select
HTML
3
star
26

svelte-favicons

A favicons generator for your web application.
HTML
3
star
27

initials-avatar

Create avatars from user initials in pure javascript
JavaScript
3
star
28

marker-clusterer-ssr

An SSR compatible implementation of Google Maps MarkerClusterer
JavaScript
2
star
29

svelte-intercom

Intercom for Svelte or Vanilla JS Apps
JavaScript
2
star
30

hapi-view-models

View model support for hapi
JavaScript
2
star
31

blemish

Super simplistic markdown parser
JavaScript
2
star
32

promise-retry

Retryable promises for node and the browser
JavaScript
1
star
33

sanity-template-sveltekit-basic

Empty Sanity SvelteKit Template
JavaScript
1
star
34

svelte-usetiful

Single tag Usetiful integration for Svelte
Svelte
1
star