2.0.0 • Published 4 years ago

react-animated-slider v2.0.0

Weekly downloads
3,484
License
MIT
Repository
github
Last release
4 years ago

react-animated-slider

npm version downloads Greenkeeper badge CircleCI dependencies devDependencies minified size minified + gzipped size

A Slider/Carousel component for React supporting custom css animations.

Demo - Codesandbox Playground

Preview

Features

  • Ready to use slider component with animations
  • Easy customization
  • Horizontal or vertical navigation
  • Swipe navigation on touch devices
  • Infinite slider
  • Autoplay
  • Supports any element as children
  • Clean DOM without dirty manipulations
  • Support for CSS modules
  • Works with SSR
  • Works on IE11

Install

npm install react-animated-slider

Note: this component relies on getDerivedStateFromProps and requires react@16.4 or newer. For older react versions please install react-animated-slider version 1:

npm install react-animated-slider@^1

Most Simple Use

import Slider from 'react-animated-slider';
import 'react-animated-slider/build/horizontal.css';

const slides = [
  { title: 'First item', description: 'Lorem ipsum'}
  { title: 'Second item', description: 'Lorem ipsum'}
];

<Slider>
  {slides.map((slide, index) => <div key={index}>
    <h2>{slide.title}</h2>
    <div>{slide.description}</div>
  </div>)}
</Slider>

Properties

propertytypedefaultdescription
slideIndexnumber0Index of the slide that will be initially displayed.
durationnumber2000(ms)Duration of the animation in milliseconds. It is used to remove the animateIn and animateOut classNames and assign current after the transition has completed.
disabledbooleanfalseDisable slider navigation
infinitebooleantrueEnable or disable infinite loop through slides. Sliders with only 2 children will have this option set to false
autoplaynumberundefinedAutoplay interval in miliseconds. If undefined the slider will not play automatically. The timer will be paused and reset during user interactions such as mouse over or touch, to avoid sliding away the elements when the user wants to click them.
touchDisabledbooleanfalseDisable slider navigation through touch events
minSwipeOffsetnumber15(px)Minimum distance in pixels to swipe for triggering a navigation event
previousButtonReactElementarrow svgWill be rendered inside the previous button
nextButtonReactElementarrow svgWill be rendered inside the next button
classNamesobjectsee belowObject representing the CSS classNames that will be apllied to the slides.
{
  slider: 'slider',
  previousButton: 'previousButton',
  nextButton: 'nextButton',
  buttonDisabled: 'disabled',
  track: 'track',
  slide: 'slide',
  hidden: 'hidden',
  previous: 'previous',
  current: 'current',
  next: 'next',
  animateIn: 'animateIn',
  animateOut: 'animateOut',
}

Classnames

classdescription
sliderelement wrapping the whole Slider
previousButtonprevious button
nextButtonnext button
buttonDisableddisabled state for previous and next button
trackelement wrapping all slides
slideapllied to every child item
hiddena slide that is not visible and is not adjacent to the current slide, therefore no animation will be applied
previousthe slide that will appear or is appearing when the slider navigated back
nextthe slide that will appear or is appearing when the slider navigated forward
animateInthe slide moving into the view
animateOutthe slide moving out of the view

Events

propertydescription
onSlideChangecalled after a slide change animation has ended. Receives an object with the new slide index as argument: <Slider onSlideChange={event => console.log(event.slideIndex)}>
2.0.0-beta.5

4 years ago

2.0.0-beta.4

4 years ago

2.0.0

4 years ago

2.0.0-beta.3

4 years ago

2.0.0-beta.2

4 years ago

2.0.0-beta.1

4 years ago

2.0.0-beta.0

4 years ago

1.1.4

5 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.5.0-beta1

6 years ago

0.5.0-beta0

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago