Slick Slider React - 无论屏幕尺寸如何,如何保持相同的宽度和空间?
我正在创建一个与 Slick Slider 反应的滑块。问题是:当屏幕尺寸发生变化时,幻灯片尺寸会减小或相互堆叠。
光滑的滑块提供:
responsive: [
{
breakpoint: 1024,
settings: {
slidesToShow: 3,
slidesToScroll: 3,
infinite: true,
dots: true
},
…
]
但这并不能阻止幻灯片大小的变化,也不能固定不断变化的幻灯片之间的边距。
我尝试过:
.slick-slide {
width: auto !important;
}
在 CSS 文件中,但随后幻灯片一层一层地累积,生成 4 行而不是 2 行。此外,动画太大,在滑块末尾创建了一个空白区域。
是否可以创建一个带有幻灯片的滑块,无论窗口大小如何,它们之间都保持相同的大小和空间?有一种方法可以保持幻灯片的固定大小,仅显示屏幕上可能的幻灯片数量并仅显示以下幻灯片的一部分(或不显示)?
这是我的代码:
const settings = {
rows: 2,
slidesPerRow: 1,
slidesToShow: 3.2,
infinite: false,
swipeToSlide: true,
slidesToScroll: 1,
lazyLoad: true,
responsive: [
{
breakpoint: 1200,
settings: {
slidesToShow: 2.5,
slidesToScroll: 2,
}
},
{
breakpoint: 1024,
settings: {
slidesToShow: 2,
slidesToScroll: 2,
}
},
{
breakpoint: 768,
settings: {
slidesToShow: 1.7,
slidesToScroll: 1,
arrows: false }
},
{
breakpoint: 480,
settings: {
slidesToShow: 1.4,
slidesToScroll: 1,
arrows: false
}
}
]
};
return (
<>
<h2>…</h2>
<div className="cell">
<Slider {...settings}>
{
this.props.data.nodes.map((node,key) => (
<Cell node={node} key={key} />
))
}
</Slider>
</div>
</>
);
谢谢!
I am creating a slider in react with Slick Slider. The problem is: when the screen size changes, the slides reduce in size or stack on top of each other.
Slick slider offers :
responsive: [
{
breakpoint: 1024,
settings: {
slidesToShow: 3,
slidesToScroll: 3,
infinite: true,
dots: true
},
…
]
But this does not prevent the change in size of the slides and does not fix the margin between the slides which are constantly changing.
I tried :
.slick-slide {
width: auto !important;
}
In the CSS file, but then the slides accumulate one under the other, generating 4 rows instead of 2. Also, the animation is too large and create a blank space at the end of the slider.
Is it possible to create a slider with slides, that keep the same size and space between them whatever the size of the window? A way to keep a fixed size of slides, showing only the number of slides possible on the screen and showing only a part (or not) of the following slides?
So as to be responsive as well. What is wanted :
Here is my code :
const settings = {
rows: 2,
slidesPerRow: 1,
slidesToShow: 3.2,
infinite: false,
swipeToSlide: true,
slidesToScroll: 1,
lazyLoad: true,
responsive: [
{
breakpoint: 1200,
settings: {
slidesToShow: 2.5,
slidesToScroll: 2,
}
},
{
breakpoint: 1024,
settings: {
slidesToShow: 2,
slidesToScroll: 2,
}
},
{
breakpoint: 768,
settings: {
slidesToShow: 1.7,
slidesToScroll: 1,
arrows: false }
},
{
breakpoint: 480,
settings: {
slidesToShow: 1.4,
slidesToScroll: 1,
arrows: false
}
}
]
};
return (
<>
<h2>…</h2>
<div className="cell">
<Slider {...settings}>
{
this.props.data.nodes.map((node,key) => (
<Cell node={node} key={key} />
))
}
</Slider>
</div>
</>
);
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
例如)
1800px 中的 4 张幻灯片
slipsToShow: _.round((width * 4) / 1800, 1 or 2);
或
https://react-slick.neostack.com/docs/example/可变宽度/
ex)
4 slides in 1800px
slidesToShow: _.round((width * 4) / 1800, 1 or 2);
or
https://react-slick.neostack.com/docs/example/variable-width/
有一个“可变宽度”选项可用于获得这种结果。查看更多: https://react-slick.neostack.com/docs/example /可变宽度
There is a "Variable width" option that can be used to get this kind of result. See more: https://react-slick.neostack.com/docs/example/variable-width