1.0.1 • Published 5 years ago

react-carousel-comp v1.0.1

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

react-carousel-comp

A light-weight React react-carousel-comp component with extremely easy API(只适用于移动端项目). Online Demo, welcome code review

Installation

npm install react-carousel-comp --save

Usage

import img1 from './static/images/11.jpg';
import img2 from './static/images/12.jpg';
import img3 from './static/images/13.jpg';
import img4 from './static/images/14.jpg';
import img5 from './static/images/15.jpg';
import Carousel from './Carousel';

// 屏幕宽度
const screenWidth = window.screen.width ||
  document.documentElement.clientWidth ||
  document.body.clientWidth;

const SOURCE = [img1, img2, img3, img4, img5];
export default class App extends PureComponent {
  render() {
    return (
      <div className="container">
        <Carousel
          index={1}
          timer={5000}
          width={screenWidth}
          infinite={true}
          className="carousel"
        >
          {
            SOURCE.map((item, key) =>
              <a
                href="javascript:;"
                className="carousel-item-a"
                key={key}
              >
                <img
                  src={item}
                  alt="轮播图"
                  className="carousel-item-a-img"
                />
              </a>
            )
          }
        </Carousel>
      </div>
    );
  }
}

props

paramdetailtypedefault
childrencollection of child nodes,array[]
widthcomponents width, isRequiorednumber
classNamecomponents className, isRequioredstring
stylecomponents styleobjectnull
indexdisplay the index in the children when initializing, starting from 1number1
timercarousel timenumber4000
infinitewhether to loopbooltrue
speedspeed of animationnumber10
indicatorClassindicator classNamestring''
visibleIndicatorwhether to display the indicatorbooltrue