[英]How to fix autoplay in slider?
I have a problem with my bxSlider.我的 bxSlider 有问题。 I initialize it at 1050px width, and also add auto-mode mode to it, and it works until the phone resolution and back to given 1050px, but when I resize it back to desktop view, slider is not working as it suppose and not touchable anymore, but auto-mode keep switching slides and goes beyond given container and by that crushes the layout.我将它初始化为 1050px 宽度,并为其添加了自动模式模式,它一直工作到手机分辨率并返回给定的 1050px,但是当我将其调整回桌面视图时,slider 无法正常工作并且不可触摸不再,但是自动模式会不断切换幻灯片并超出给定的容器,从而破坏布局。 Help.帮助。
Nothing in the SCSS file. SCSS 文件中没有任何内容。 In HTML just a container with 4 items in it.在 HTML 中只是一个装有 4 件物品的容器。 Here is the jQuery function.这是 jQuery function。
$(function () {
var autoMode = false;
var slider = $('.list-product').bxSlider({
maxSlides: 4,
moveSlides: 1,
responsive: true,
slideWidth: 236,
speed: 900,
pause: 1700,
auto: autoMode,
pager: false,
infiniteLoop: true,
touchEnabled: true,
});
if ($(window).width() > 1050) {
slider.destroySlider();
}
$(window).resize(function () {
if ($(window).width() < 1050) {
slider.reloadSlider();
autoMode = true;
} else {
slider.destroySlider();
autoMode = false;
}
});
});
Why are you destroying the slider again on >1050.... You could also do it without the autoMode variable.你为什么要在 >1050 上再次破坏 slider .... 你也可以在没有 autoMode 变量的情况下这样做。 The documentation also provides a startAuto function.该文档还提供了 startAuto function。
var slider = $('.list-product').bxSlider({
maxSlides: 4,
moveSlides: 1,
responsive: true,
slideWidth: 236,
speed: 900,
pause: 1700,
pager: false,
infiniteLoop: true,
touchEnabled: true,
});
if ($(window).width() < 1050) {
slider.startAuto();
}
$(window).resize(function(){
if ($(window).width() < 1050) {
slider.startAuto();
} else {
slider.stopAuto();
}
});
you can try to only run the slider code when the screen is below 1050px:您可以尝试仅在屏幕低于 1050 像素时运行 slider 代码:
$(function(){
$(window).resize(function(){
if ($(window).width() < 1050) {
var autoMode = false;
var slider = $('.list-product').bxSlider({
maxSlides: 4,
moveSlides: 1,
responsive: true,
slideWidth: 236,
speed: 900,
pause: 1700,
auto: autoMode,
pager: false,
infiniteLoop: true,
touchEnabled: true,
});
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.