svelte-carousel

A super lightweight, super simple Carousel for Svelte 3

Github星跟蹤圖

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 greater than or equal to the number of slides in your carousel, autoplay, integer, 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, 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., 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>

主要指標

概覽
名稱與所有者beyonk-group/svelte-carousel
主編程語言Svelte
編程語言JavaScript (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2018-08-28 18:03:26
推送於2022-05-05 10:16:15
最后一次提交2022-05-05 11:16:15
發布數24
最新版本名稱v2.9.0 (發布於 2022-01-13 16:19:45)
第一版名稱v1.1.0 (發布於 2018-10-14 11:55:57)
用户参与
星數213
關注者數6
派生數38
提交數96
已啟用問題?
問題數55
打開的問題數20
拉請求數19
打開的拉請求數3
關閉的拉請求數6
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?