D
D
Damaks2015-12-14 15:06:31
JavaScript
Damaks, 2015-12-14 15:06:31

How to rotate tabs in Bootstrap?

Implemented tabs according to the getbootstrap.com/javascript/#tabs docs .
It is necessary to make automatic rotation of an arbitrary number of tabs. The number of tabs on different pages is different. When a user clicks on any tab, the rotation stops.
Is there a ready or approximate way to implement it? Surely someone has come across.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2015-12-14
@Damaks

a little homocode))

$(document).ready(function(){
    var timer, tabs = $('a[data-toggle="tab"]');
    if(tabs) {
        var i = 1, tabs_count = tabs.length-1;
        timer = setInterval(function(){
            $(tabs[i]).tab('show');
            if(i === tabs_count){
                i = 0;
            } else {
                i++;    
            }
        }, 1000);
    }
    
    $('li').click(function(e){
        clearInterval(timer);
    });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question