bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Carousel does not work properly if there is only 1 item

Open msmeeks opened this issue 14 years ago • 3 comments

If a carousel only has one item and the controls are displayed, they still trigger a next or previous slide. The next or previous carousel item, however, does not exist so a really small blank item is displayed.

Admittedly, this issue can be handled by not showing the controls if there is only one item. This gets a bit tricky if the items are generated dynamically or if they change after the carousel has been created.

Suggestion: The carousel controls should do nothing if there is no next or previous item or it should go to the same page. The first option is preferable.

msmeeks avatar Feb 15 '12 15:02 msmeeks

Hey, you shouldn't initialize the carousel if there is only 1 element. Bit I had the same problem, so thi is how i solved this

$('.carousel').each(function() {
        if($(this).find('.carousel-inner .item').length > 1){
            $(this).carousel({interval: 10000})
                .hover( function () {$(this).carousel('pause')}, 
                        function () {$(this).carousel('cycle')});

        }
        else{
            $(this).find('.carousel-control').hide();
        }
    });

-- close

simonfranz avatar Feb 15 '12 16:02 simonfranz

The Carousel should natively handle this without the need for manual workarounds.

tmchow avatar Feb 15 '12 23:02 tmchow

fixed in 2.0.1-wip

fat avatar Feb 17 '12 04:02 fat