bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Nav Tabs inside Carousel breaks Carousel

Open ravikanchikare opened this issue 14 years ago • 11 comments

Nav Tabs inside Carousel breaks Carousel. its due to active class in both Carousel and tabs

I will upload an example here soon.

ravikanchikare avatar Feb 23 '12 11:02 ravikanchikare

Currently the carousel doesn't support tabs, or any other component, within it. We'll swing back around to this in a future release.

mdo avatar Apr 14 '12 20:04 mdo

Carousel inside tabs doesn't work either.

the carousel in the first active tab works, but once the tab is off and on again, the carousel stops working

heronog avatar May 02 '12 17:05 heronog

I've encountered this too.

carltongibson avatar May 04 '12 09:05 carltongibson

to make carousels work inside tabs you need to change the CSS of the tabs

by default, tab-pane has a display:none style that confuses the carousel (as its container has no dimensions)

if you change your tab-pane styles to:

display: block; position: relative; left: -10000px;

and your .tab-pane.active styles to:

left: 0;

it should work. it works for me

heronog avatar May 04 '12 15:05 heronog

El problema es que el carousel se reproduce al estar el tab oculto, se debe detener para evitar el error.

The problem is that the carousel plays the tab to be hidden, must be stopped to avoid the error.

$(document).ready(function() {

            $('a[data-toggle="tab"]').on('shown', function (e) {
                switch(e.currentTarget.hash){
                    case '#tab0':
                        $('#myCarousel1').carousel('pause')
                        $('#myCarousel2').carousel('pause')
                        $('#backMenu').css('background-image','url("./img/back0.png")');
                    break;
                    case '#tab1':
                        $('#myCarousel0').carousel('pause')
                        $('#myCarousel2').carousel('pause')
                            $('#backMenu').css('background-image','url("./img/back1.png")');
                    break;
                    case '#tab2':
                        $('#myCarousel0').carousel('pause')
                        $('#myCarousel1').carousel('pause')                         
                        $('#backMenu').css('background-image','url("./img/back2.png")');
                    break;                      
                }

})

carloscba avatar May 15 '12 20:05 carloscba

The real problem is that the TAB searches for a .active class and just deletes it from the elements it finds. The selector used to get the active tab should be more specific to only get the .active element that is a direct descendant of the tabs container.

heronog avatar May 15 '12 21:05 heronog

if you don't set interval and the carousel is used once change to autoplay. You can test this in a simple carousel. When change item on a hidden tab the class .next, .prev asigned to item div broken the carousel.

carloscba avatar May 15 '12 23:05 carloscba

@heronog your css fix didn't work for me because it was stacking the tab-pane elements on top of each other. What I did to fix this was changed the css to the following:

.tab-content > .tab-pane,
.pill-content > .pill-pane {
    position: absolute;
    opacity: 0;
    z-index:0;
}
.tab-content > .active,
.pill-content > .active {
    opacity: 1;
    z-index:1;
}

tramck avatar Jun 14 '12 15:06 tramck

Cool. that works too but.

I just think that changing the opacity of an element to 0 makes it invisible but it's still clickable, so make sure you move the active tab pane to the front to avoid "ghost" elements from the other panes

heronog avatar Jun 14 '12 15:06 heronog

Yeah that's why I added the z-index.

tramck avatar Jun 14 '12 17:06 tramck

using z-index solved my problem too. Earlier when using tabs with display block/none other tabs except first tab din't worked.

sajaldas avatar Oct 21 '14 10:10 sajaldas