简体   繁体   English

初始化后添加更多图像时,React-slick 滑块会变形

[英]React-slick slider gets distorted when adding more images after initialisation

I am using the React-slick slider to display the images given by the random user API.我正在使用 React-slick 滑块来显示随机用户 API 给出的图像。 I followed the steps given on the npm page for the react slider and installed the slick carousel and added the two CSS files to the component.我按照 npm 页面上为反应滑块给出的步骤安装了光滑的轮播并将两个 CSS 文件添加到组件中。

I wanted to add more images to the existing slider if the user clicked on the next arrow or dragged the slider to the left, so im using the afterChange callback to update my state so that the useEffect having this state value as the second argument can be called and then concat the previous data with the new data.如果用户单击下一个箭头或将滑块向左拖动,我想向现有滑块添加更多图像,因此我使用afterChange回调来更新我的状态,以便具有此状态值作为第二个参数的 useEffect 可以是调用,然后将以前的数据与新数据连接起来。

Here I noticed when the user clicks next or drags the slider to the left sometimes there is a distortion.在这里,我注意到当用户单击下一步或向左拖动滑块时,有时会出现失真。

https://stackblitz.com/edit/react-nlxodz has one slider and one text line below it, slide the slider continuously and you can see that for a few brief seconds the text under the slider gets pushed even further down and then comes back up to the original place. https://stackblitz.com/edit/react-nlxodz有一个滑块和它下方的一个文本行,连续滑动滑块,您可以看到在几秒钟内滑块下方的文本被进一步向下推,然后出现回到原来的地方。

Documentation suggests the below CSS if there is a flex prop on the slider.如果滑块上有 flex 属性,文档会建议使用以下 CSS。 However, my code doesn't have flex properties.但是,我的代码没有 flex 属性。

Flexbox support
If you have flex property on container div of slider, add below css

* {
  min-height: 0;
  min-width: 0;
}

is this issue raised because of the way im adding data to the slider or an issue with the CSS?这个问题是因为我向滑块添加数据的方式还是 CSS 问题引起的? is there a solution where that distortion is not shown when the user swipes or slides very fast?当用户快速滑动或滑动时,是否有不显示失真的解决方案?

Wrap Slider with divdiv包裹Slider

 <div style={{ backgroundColor: "green", height: "140px" }}>
          <Slider {...settings}>
            {rowData.map(i => (
              <div>
                <img src={i.picture.large} />
              </div>
            ))}
          </Slider>
        </div>
        <div>KEEP AN EYE ON THIS TEXT WHILE SCROLLING</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM