Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@beyonk/svelte-carousel

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@beyonk/svelte-carousel

A super simple infinite carousel

  • 1.5.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Beyonk

js-standard-style CircleCI

Carousel which uses flexbox, and will scale to its largest piece of content.

Demo

To run a demo, check this project out and run npm run dev

Usage

To use within any Javascript project

Simply install the package and require it in your javascript (or require it from CDN)

npm i -D @beyonk/svelte-carousel
<script src="node_modules/@beyonk/svelte-carousel/lib/carousel.js"></script>

<!-- or -->
<script src="//unpkg.com/@beyonk/svelte-carousel@latest/lib/carousel.js"></script>

To use within a Svelte application:

npm i -D @beyonk/svelte-carousel
import Carousel from '@beyonk/svelte-carousel/src/components/carousel/component.svelte'
import Slide from '@beyonk/svelte-carousel/src/components/slide/component.svelte'

export default {
	components: {
		Carousel,
		Slide
	}
}

Usage

<Carousel current="3">
	<Slide>
		<h2>1</h2>
	</Slide>
	<Slide>
		<h2>2</h2>
	</Slide>
	<Slide>
		<h2>3</h2>
	</Slide>
	<Slide>
		<h2>4</h2>
	</Slide>
	<Slide>
		<h2>5</h2>
	</Slide>
	<Slide>
		<h2>6</h2>
	</Slide>
</Carousel>

The current parameter is a 1-indexed number into your list of slides. The carousel will start on this slide.

Customising controls

You can customise the controls by filling their slots. If you don't include slots, the default controls will be used:

<Carousel current="1">
	<button slot="prev">&lt; Prev</button>
	<button slot="next">Next &gt;</button>
	<Slide>
		<h2>1</h2>
	</Slide>
	...
	<Slide>
		<h2>9</h2>
	</Slide>
</Carousel>

Autoplay

You can cause the carousel to autoplay by setting the value of the autoplay to a millisecond amount.

<Carousel ref:carousel current="1" autoplay="1000">
	<button slot="prev">&lt; Prev</button>
	<button slot="next">Next &gt;</button>
	<Slide>
		<h2>1</h2>
	</Slide>
	...
	<Slide>
		<h2>9</h2>
	</Slide>
</Carousel>

You can also manually pause and start the carousel by calling the component methods:

	const { carousel } = this.refs // We grab a component reference from the 'ref:carousel' attribute above.
	carousel.start()
	carousel.stop()

Thanks

Huge thanks to Nick A Walsh for his original carousel, Rich Harris for his immense work on Svelte, and Stu Plumbley for his limitless flexbox expertise.

FAQs

Package last updated on 30 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc