响应式属性不适用于反应光滑

时间:2019-02-04 12:03:39

标签: javascript css reactjs slider

我想在小型设备上更改sliderToShow属性,但是responsive属性不起作用。

let settings_3 = {
  dots: false,
  autoplay: false,
  autoplaySpeed: 3000,
  slidesToShow: 3,

  responsive: [{
    breakpoint: 600,
    settings_3: {
      slidesToShow: 2,
      slidesToScroll: 2,
      initialSlide: 2
    }
  }]
};

1 个答案:

答案 0 :(得分:0)

settings_3内将settings更改为responsive[]。光滑的没有settings_3属性:

class SimpleSlider extends React.Component {
  render() {
    let settings_3 = {
      dots: false,
      autoplay: false,
      autoplaySpeed: 3000,
      slidesToShow: 3,

      responsive: [{
        breakpoint: 600,
        settings: {
          slidesToShow: 2,
          slidesToScroll: 2,
          initialSlide: 2
        }
      }]
    };
    return (
      <Slider {...settings_3}>
        <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>
    );
  }
}

ReactDOM.render( <SimpleSlider/> ,
  document.getElementById('root')
);
#root{
text-align: center;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick.min.css" rel="stylesheet" />

<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick-theme.min.css" rel="stylesheet" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/react-slick/0.13.1/react-slick.js"></script>

<div id='root'></div>