1.3.6 • Published 6 years ago

tnt-carousel v1.3.6

Weekly downloads
32
License
MIT
Repository
github
Last release
6 years ago

tnt-carousel

Super simple responsive carousel with touch support

Join the chat at https://gitter.im/reinvanoyen/tnt-carousel

Designed to be used with browserify.

There's a huge amount of carousel scripts out there, I'm fully aware of that. But not many carousels work well with percentages, fluid layouts and media queries. This carousel makes it possible to style your carousel like you want. If you want to have 2 slides in view, just style your childs to have a width of 50%. If you want it to only have 1 slide in view on mobile, just style your childs to have a width of 100%. The carousel will adapt accordingly.

Getting started

Install using npm:

$ npm install tnt-carousel

Add it to your Javascript:

var Carousel = require('tnt-carousel');
new Carousel(document.getElementById( 'my-carousel' ), {
	autoplay: true,
	autoplayInterval: 5000
});

Add your HTML markup. Note that you can use any structure you want, as long as it's an element containing childs as slides. Using an unordered list or a section containing multiple articles are also good options.

<div id="my-carousel">
	<div>This is slide #1</div>
	<div>This is slide #2</div>
	<div>This is slide #3</div>
	<div>This is slide #4</div>
	<div>This is slide #5</div>
	<div>This is slide #6</div>
	<div>This is slide #7</div>
</div>

Add some super basic styling to get started. Don't forget to add your transition to the container!

#my-carousel
{
	overflow: hidden;
	position: relative;
	transition: transform .5s;
}

#my-carousel div
{
	float: left;
	width: 25%;
	height: 300px;
}

.carousel-prev-button,
.carousel-next-button
{
	position: absolute;
	top: 50%;
	width: 30px;
	height: 30px;
	margin-top: -15px;
}

.carousel-prev-button { left: 0; }
.carousel-next-button { right: 0; }

Options

OptionTypeDefaultDescription
activeSlideClassstringactiveThe currently active slide will have this class assigned
arrowButtonsbooleantrueWhether or not to automatically add a previous and next button
arrowButtonsContainerElementnullThe HTML Element to append the arrow buttons to
autoplaybooleanfalseWhether or not to automatically start playing once the carousel is built
autoplayIntervalint4000The time interval (in milliseconds) between each slide
edgeFrictionnumber0.1Determines the distance (width of slide * edgeFriction) to swipe before it is registered as a request to a new slide. A value between 0.1 and 0.3 feels natural.
inactiveArrowClassstringhideIf option arrowButtons is set to true, the inactive arrows will have this class assigned
keyEventsbooleanfalseWheter or not to use keyboard events
loadedClassstringloadedWhen the carousel is built it will have this class assigned
mouseSwipebooleantrueWhether or not to use mouse events for swiping
nextArrowClassstringcarousel-next-buttonIf option arrowButtons is set to true, the next arrow will have this class assigned
previousArrowClassstringcarousel-prev-buttonIf option arrowButtons is set to true, the previous arrow will have this class assigned
touchSwipebooleantrueWhether or not to use touch events for swiping

Methods

build

Build the carousel. Gets called automatically upon creating an instance. Useful to rebuild previously destroyed carousels.

var carousel = new Carousel(document.getElementById( 'my-carousel' ));
carousel.destroy();
carousel.build();

destroy

Destroys a carousel after it's been built. This restores the DOM to it's original state.

carousel.destroy();

goTo

Slide to a certain slide

carousel.goTo( 3 );

play

Automatically go from one slide to the other

carousel.play();

pause

Pause the carousel if it's playing

carousel.pause();
1.3.6

6 years ago

1.3.5

9 years ago

1.3.4

9 years ago

1.3.3

9 years ago

1.3.2

9 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.9

9 years ago

1.2.8

9 years ago

1.2.7

9 years ago

1.2.6

10 years ago

1.2.5

10 years ago

1.2.4

10 years ago

1.2.3

10 years ago

1.2.2

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.9

10 years ago

1.1.8

10 years ago

1.1.7

10 years ago

1.1.6

10 years ago

1.1.5

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago