[英]Swiper: update slides width when slider width change
I have a slider that change it's width when user click on next button for the first time:我有一个 slider 当用户第一次点击下一步按钮时改变它的宽度:
CSS CSS
#project-slider {
height: 100vh;
width: calc(100vw - 100px);
position: absolute;
right: 0;
top: 0;
transition: width 0.5s;
&.wide {
width: 100vw;
}
.swiper-slide {
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 100vh;
}
}
And JS和 JS
slider.on('slideChange', function(){
if(slider.activeIndex == 0){
$(slider.$el).removeClass('wide');
}else{
$(slider.$el).addClass('wide');
}
});
But how can I change the slide width when this happens?但是发生这种情况时如何更改幻灯片宽度? How can I avoid show part of the next slide?
如何避免显示下一张幻灯片的一部分?
https://codepen.io/marcelo2605/pen/KKKZVvq?editors=0010 https://codepen.io/marcelo2605/pen/KKKZVvq?editors=0010
Found a solution using transform:translateX(100px)
to hide part of the slider.找到了一个解决方案,使用
transform:translateX(100px)
隐藏 slider 的一部分。 This is not the best solution, so I'm open to another suggestions.这不是最好的解决方案,所以我愿意接受其他建议。
https://codepen.io/marcelo2605/pen/KKKZVvq?editors=0110 https://codepen.io/marcelo2605/pen/KKKZVvq?editors=0110
If you want your slide to work properly, just change the width of the.wide, like this:如果您希望幻灯片正常工作,只需更改.wide 的宽度,如下所示:
#project-slider {
height: 100vh;
width: calc(100vw - 100px);
position: absolute;
right: 0;
top: 0;
transition: width 0.5s;
&.wide {
width: calc(100vw - 100px); //the change
}
.swiper-slide {
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 100vh;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.