user3792128
user3792128

Reputation: 21

Disable bxSlider if there is only one slide

I have a slider on all of my pages, but I would like to disable it if there is only one slide. I've tried a few different things but can't seem to get it to work correctly. Here is the code I am using:

    var slider = $('.bxslidertwo').bxSlider({
    pager: true,
    pagerType:'full',
    autoHidePager: true,

});

var numberOfImages = $('.bxslidertwo li').length;

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

Any help that can be offered with this would be greatly appreciated.

Upvotes: 0

Views: 3856

Answers (1)

jjjjjjjjjjjjjjjjjjjj
jjjjjjjjjjjjjjjjjjjj

Reputation: 3118

Does instantiating it only if there is an image work? In that case, try this:

var numberOfImages = $('.bxslidertwo li').length;

if( numberOfImages > 1 ) {

    var slider = $('.bxslidertwo').bxSlider({
        pager: true,
        pagerType:'full',
        autoHidePager: true,

    });

}

Upvotes: 3

Related Questions