项目作者: aprilmintacpineda

项目描述 :
Carousel component for ReactJS.
高级语言: JavaScript
项目地址: git://github.com/aprilmintacpineda/react-carousel.git
创建时间: 2018-09-15T10:27:13Z
项目社区:https://github.com/aprilmintacpineda/react-carousel

开源协议:MIT License

下载


react-carousel

Carousel component for reactJS.

See Demo.

install

  1. npm i -s react-carousel js-carousel

Usage

On your main entry file:

  1. import 'js-carousel';

Then, whenever you want to use the component.

  1. import ReactCarousel from 'react-carousel';

Then:

  1. <ReactCarousel animationSpeed={500} itemDuration={5000} swipeThreshold={150}>
  2. <img src="path-to-image" />
  3. <img src="path-to-image" />
  4. <img src="path-to-image" />
  5. <img src="path-to-image" />
  6. <img src="path-to-image" />
  7. </ReactCarousel>

You can also specify a className for the container of the carousel by providing a className prop to it.

  • animationSpeed is the speed (in terms of milliseconds) of the transition animation.
  • itemDuration is the amount of time (in terms of milliseconds) it has to wait before transitioning to the next item.
  • swipeThreshold is the sensitivity of swipe, the lower the number the more sensitive the swipe will be, you don’t want it to be very high otherwise the users would have a hard time navigating around using swipe. You don’t want it to be very low, otherwise a click might become enough to navigate around using swipe. I suggest starting at 150 and tweaking it from there according to how you like it.

If you expect your images to change (you can see this on the demo), you should provide a key to the component and make sure that the key is different for every changes like so:

  1. <ReactCarousel
  2. key={this.state.carouselImages.key}
  3. animationSpeed={500}
  4. itemDuration={5000}
  5. swipeThreshold={150}>
  6. {this.state.carouselImages.srcs.map(src => {
  7. <img key={src} src={src} />;
  8. })}
  9. </ReactCarousel>
  1. // upon updating
  2. this.setState({
  3. carouselImages: {
  4. // the key would be different from the last one
  5. key: this.state.carouselImages.key + 1,
  6. src
  7. }
  8. });

react-carousel uses js-carousel.