javascript bx 滑块:如何在只有一张图像时禁用幻灯片放映

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24654670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 03:10:29  来源:igfitidea点击:

bx slider : how to disable slide show when only one image is present

javascriptjquerybxslider

提问by Vysakh V K

I am using bxsliderto create a slideshow of my images. The images are updating dynamically. My problem is the sideshow fade-in and fade-out work even only one image is present. How can I stop this ?

我正在使用bxslider创建我的图像的幻灯片。图像正在动态更新。我的问题是即使只有一张图像,杂耍的淡入和淡出也能正常工作。我怎么能阻止这个?

bxslider options are

bxslider 选项是

   var coverSlider = $('.bxslider').bxSlider({
        auto: true,
        minSlides: 1,
        maxSlides: 1,
        pager: false,
        speed: 500,
        pause: 3000,
        autoHover: true,
        mode: 'fade',
        controls: false
   })

I am using reload method to update the slider when a new image is appends or removes

我正在使用重新加载方法在添加或删除新图像时更新滑块

 coverSlider.reloadSlider();

采纳答案by Nicolas R

You should check the number of images before reloading, and use destroySlider()method if there is only 1 image.

重新加载之前应该检查图像的数量,destroySlider()如果只有 1 个图像,则使用方法。

// Get the quantity of images (add your code if you want an example)
var numberOfImages = ...;

if (numberOfImages > 1) {
    coverSlider.reloadSlider();
} else {
    coverSlider.destroySlider();
}

回答by Sonjoe

this helps me:

这对我有帮助:

$(document).ready(function(){
  $('.bxslider').bxSlider({
    mode: 'fade',
    auto: ($(".bxslider li").length > 1) ? true: false,
    pager: ($(".bxslider li").length > 1) ? true: false,
    controls: false
  });
});

回答by yubase

var numImgs = $('div.bxslider img').length;
if (numImgs > 1) {
    $('.bxslider ').bxSlider({
        controls: true,
        ...
    });
}

回答by Anto King

Try

尝试

var numImgs = $('div.myClassName img').length;
if(numImgs>1)
{
\Do your bxslider reload here
}

Instead you can use Jquery Selector too like below

相反,您也可以使用 Jquery Selector,如下所示

jQuery(".image").Length

Hope this helps...

希望这可以帮助...

Click here to read about selectors Click

单击此处阅读有关选择器的信息单击

回答by Bavarac

This solution works for me Change auto: true to

此解决方案适用于我 Change auto: true to

    auto: ($('#slidername').children().length < 2) ? false : true    

Thanks to https://github.com/stevenwanderski/bxslider-4/issues/607

感谢https://github.com/stevenwanderski/bxslider-4/issues/607

回答by Elena Calimac

bx slider : how to disable slide show when only one image is present?

bx 滑块:如何在只有一张图像时禁用幻灯片放映?

Set auto to false:

将自动设置为假:

   var coverSlider = $('.bxslider').bxSlider({
        auto:false
   })