Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 5, 2022. It is now read-only.

A super lightweight, super simple Carousel for Svelte 3

License

NotificationsYou must be signed in to change notification settings

beyonk-group/svelte-carousel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Svelte Carousel

js-standard-styleCircleCIsvelte-v2svelte-v3

Svelte Carousel / Slider

This is a ground-up rewrite of the original Svelte Carousel/Slider using Svelte v3, andSiema, 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

Thesimplest possible demo

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

To use within a Svelte application:

npm i -D @beyonk/svelte-carousel

Usage

<Carousel><divclass="slide-content">Slide 1</div><divclass="slide-content">Slide 2</div><divclass="slide-content">Slide 3</div><divclass="slide-content">Slide 4</div></Carousel><script>importCarouselfrom'@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><spanclass="control"slot="left-control"><ChevronLeftIcon/></span><divclass="slide-content">Slide 1</div>  ...<divclass="slide-content">Slide n</div><spanclass="control"slot="right-control"><ChevronRightIcon/></span></Carousel><script>importCarouselfrom'./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:

AttributeTypeDefault ValueDescription
loopbooleantrueAt the end of the carousel, loop through to the first slide again, seamlessly
perPageinteger3Number of slides on a single page. Note that this needs to be less than or equal to the number of slides in your carousel
autoplayinteger0Auto-change slide at an interval (in milliseconds). 0 means don't autoplay.
durationnumber200Slide transition duration in milliseconds.
easingstring'ease-out'It is like a CSS transition-timing-function — describes acceleration curve.
startIndexnumber0Index (zero-based) of the starting slide.
draggablebooleantrueUse dragging and touch swiping.
multipleDragbooleantrueAllow dragging to move multiple slides.
dotsbooleantrueToggles visibility of slider dots.
controlsbooleantrueToggles visibility of slider controls. dots.
thresholdnumber20Touch and mouse dragging threshold (in px).
rtlbooleanfalseEnables 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:

<CarouselperPage={{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:

NameDataDescription
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

<Carouselbind:this={carousel}on:mouseenter={enter}on:mouseleave={leave}><divclass="slide-content">Slide 1</div>...<divclass="slide-content">Slide n</div></Carousel><script>importCarouselfrom'./Carousel.svelte'letcarousel;functionenter(){carousel.pause();}functionleave(){carousel.resume();}</script>

About

A super lightweight, super simple Carousel for Svelte 3

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors14


[8]ページ先頭

©2009-2025 Movatter.jp