'bx slider destroy when less than 4 slides
I'm using BX slider on a project and having some trouble with the destroy.slider() method - my client is adding images via a CMS, so there is a variable # of slides for each instance of the slider. I'm trying to kill the slider when there are fewer than 5 slides and return to the normal state of display (which is a grid without any controls). After reading the documentation, I thought this would work, but no luck - the slider stays in tact, even though getSlideCount is returning 2. Any suggestions are welcome!
Thanks!
var slider = $('#view-profiles').bxSlider({
minSlides: 4,
maxSlides: 4,
nextSelector: '.next',
prevSelector: '.back',
slideWidth: '220px',
pager: false,
slideMargin: '0',
nextText: '',
prevText: '',
infiniteLoop:false,
hideControlOnEnd: true
});
if (slider.getSlideCount() < 5){
slider.destroySlider();
}
Solution 1:[1]
try this
var total_slide = slider.getSlideCount() ;
if (total_slide < 5){
slider.destroySlider();
}
or
var slider = $('#view-profiles').bxSlider({
minSlides: 4,
maxSlides: 4,
nextSelector: '.next',
prevSelector: '.back',
slideWidth: '220px',
pager: false,
slideMargin: '0',
nextText: '',
prevText: '',
infiniteLoop:false,
hideControlOnEnd: true,
onSliderLoad:function()
{
if (slider.getSlideCount() < 5){
slider.destroySlider();
}
}
});
Solution 2:[2]
if($('#view-profiles > div').length > 4){
var slider = $('#view-profiles').bxSlider({
minSlides: 4,
maxSlides: 4,
nextSelector: '.next',
prevSelector: '.back',
slideWidth: '220px',
pager: false,
slideMargin: '0',
nextText: '',
prevText: '',
infiniteLoop:false,
hideControlOnEnd: true
});
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Ashish Mehta |