Created
November 13, 2013 21:40
-
-
Save lutsen/7456894 to your computer and use it in GitHub Desktop.
A function to initiate a dynamically generated Bootstrap 3.0.2 carousel. The function adds an .active class to the first item, and adds carousel-indicators li elements for all carousel items. Handy if all carousel item code needs to be the same, or you don't know how many items your carousel will have.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setupCarousel() { | |
$('.carousel').each(function() { | |
// Add active class to first item | |
$(this).find('.carousel-inner .item').first().addClass('active'); | |
// Add indicators to carousel | |
for (var i = 0; i < $(this).find('.carousel-inner .item').length; i++) { | |
$(this).find('.carousel-indicators').append('<li data-target="#your-carousel-id" data-slide-to="'+i+'" class="text-shadow"></li>'); | |
} | |
// Add active class to first indicator | |
$(this).find('.carousel-indicators li').first().addClass('active'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment