ReactSlick(React轮播图插件)

React Slick

官网:https://react-slick.neostack.com/

基本使用:
	安装:npm install react-slick --save   或   yarn add react-slick
	安装包含css的文件:npm install slick-carousel --save
import "~slick-carousel/slick/slick.css"; 
import "~slick-carousel/slick/slick-theme.css";
示例:
类组件
import React, { Component } from "react";
import Slider from "react-slick";

export default class SimpleSlider extends Component {
  render() {
    const settings = {
      dots: true,
      infinite: true,
      speed: 500,
      slidesToShow: 1,
      slidesToScroll: 1
    };
    return (
      <div>
        <h2> Single Item</h2>
        <Slider {...settings}>
          <div>
            <h3>1</h3>
          </div>
          <div>
            <h3>2</h3>
          </div>
          <div>
            <h3>3</h3>
          </div>
          <div>
            <h3>4</h3>
          </div>
          <div>
            <h3>5</h3>
          </div>
          <div>
            <h3>6</h3>
          </div>
        </Slider>
      </div>
    );
  }
}
函数组件
import Slider from "react-slick";
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";
import './index.css';

function SimpleSlider() {
    const settings = {
        dots: true,//是否显示小圆点索引
        autoplay: true,//是否自动播放
        infinite: true,//是否无限循环
        autoplaySpeed: 2000,//自动播放的时间
        fade: true,//是否采用淡入淡出的效果
        slidesToShow: 1,
        slidesToScroll: 1
    };
    return (
        <div className='swiper-content'>
            <h2> Single Item</h2>
            <Slider {...settings} className="swiper-container">
                <div>
                    <h3>1</h3>
                </div>
                <div>
                    <h3>2</h3>
                </div>
                <div>
                    <h3>3</h3>
                </div>
            </Slider>
        </div>
    )
}
export default SimpleSlider;

效果如下
ReactSlick(React轮播图插件)_第1张图片

你可能感兴趣的:(轮播图,react.js)