Basically worked out the index of the currently shown slide, then used that index to apply the 'active' class to the respective navigation button.
$('#myCarousel').bind('slid', function() {
// Get currently selected item
var item = $('#myCarousel .carousel-inner .item.active');
// Deactivate all nav links
$('#carousel-nav a').removeClass('active');
// Index is 1-based, use this to activate the nav link based on slide
var index = item.index() + 1;
$('#carousel-nav a:nth-child(' + index + ')').addClass('active');
});
You can clearly optimise the code to use less variables. However, I've deliberately expanded it so that you understand what's going on.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…