Updated bootply
基本上,你需要利用slid.bs.carousel
事件的bootstrap-carousel
,并获取当前carousel slide
的指数,与指数找到div element
您的#hot_news
元素在div.row
下,并将active
类添加到它。同时,在添加之前,从div.row
下的所有其他divs
中删除active class
。
以下是你如何做到这一点。
$('#carousel-example-generic').on('slid.bs.carousel', function (e) {
var currentIndex = $(e.relatedTarget).index();
$("#hot_news .row div.active").removeClass('active');
$("#hot_news .row div").eq(currentIndex).addClass('active');
});
$(document).ready(function(){
$("#hot_news .row div").eq(0).addClass('active'); //add to 0 by default on page load
});
CSS
#hot_news .active{
background-color: #034121;
}
使用#034121背景颜色的。主动类和当前幻灯片添加类名。 – vrn53593