【发布时间】:2026-02-02 18:50:01
【问题描述】:
我的光滑滑块在初始化和更改屏幕分辨率时宽度错误。
我的js:
$('.slider').slick({
infinite: false,
speed: 300,
initialSlide: 1,
slidesToShow: 3,
slidesToScroll: 1,
dots: false,
responsive: [{
breakpoint: 1024,
settings: {
slidesToShow: 2
}
}, {
breakpoint: 650,
settings: {
initialSlide: 2,
slidesToShow: 1
}
}]
});
我的 CSS:
.sub-slider {
width: 100%;
display: flex;
flex-flow: column;
.slider {
display: flex;
flex-flow: row;
justify-content: center;
align-content: center;
align-items: center;
min-width:500px;
.sub-box {
text-align: center;
padding-top: 45px;
cursor:pointer;
.title {
color: #6deca0;
font-family: "AmsiProNarw", sans-serif;
font-size: 48px;
font-style: italic;
font-weight: 800;
}
.price {
color: #393939;
font-family: "AmsiProNarw", sans-serif;
font-size: 18px;
font-style: italic;
font-weight: 800;
}
.sub-slider-btn {
margin: 60px 20px;
border-color: #eaeaea!important;
background-color: #fdfdfd!important;
color: #686868!important;
}
}
.sub-box:hover {
transition: border .2s;
border-bottom: 14px solid #6deca0;
.sub-slider-btn{
border-color: #6deca0!important;
background-color: rgba(108,235,159,.2)!important;
color: #393939!important;
}
}
}
.sub-slider-confirmation-btn-wrp {
align-self: center;
display: none;
.sub-slider-confirmation-btn {
cursor:pointer;
$margin: 20px;
$height: 45px;
height: $height;
width: 80px;
border: 1px solid #ccc;
border-radius: 8px;
margin: $margin $margin $margin $margin;
text-align: center;
line-height: $height;
font-weight: 800;
}
}
}
这就是它的加载方式,即使我指定了slidesToShow: 3。
我不确定如何解决这个问题。我已经阅读了这些,没有修复:
Slick slider wrong width on initialization
Slick carousel loads the wrong width on initialization
https://github.com/kenwheeler/slick/issues/790
https://github.com/kenwheeler/slick/issues/1180
https://github.com/kenwheeler/slick/issues/2167
编辑:
我做了一个小提琴https://jsfiddle.net/simeydotme/fmo50w7n/
它似乎在小提琴中工作,但在我的网站上却不行。也许我继承了一些糟糕的CSS?但我现在一直在尝试调试这个 5 小时。而且我找不到任何解决方案..
【问题讨论】:
-
尝试改变重新加载页面的宽度
-
@BilalHussain 请进一步解释
-
“My css: ...” - slick 带有自己的样式表,可以应用其工作所需的基本样式。现在,当我看到您覆盖滑块使用的基本类的属性时,我首先会质疑您是否自己添加了这些属性。
-
它的
css工作有一些定义的大小。如果您只是使用浏览器最大化按钮或调整大小工具调整浏览器的大小,那么在达到定义的点之前它可能无法按预期工作。我建议您使用模拟器来检查响应性或使用实时设备来验证相同..
标签: javascript jquery html css slick.js