我正在使用OWL Carousel,尝试在每次幻灯片时将课程添加到当前项目<div class="item">
。
JS:
$(document).ready(function() {
$("#owl-demo").owlCarousel({
items : 4,
lazyLoad : true,
navigation : true
});
});
HTML:
<div id="owl-demo" class="owl-carousel">
<div class="item"><img class="lazyOwl" data-src="assets/owl1.jpg" alt="Lazy Owl Image"></div>
<div class="item"><img class="lazyOwl" data-src="assets/owl1.jpg" alt="Lazy Owl Image"></div>
<div class="item"><img class="lazyOwl" data-src="assets/owl2.jpg" alt="Lazy Owl Image"></div>
<div class="item"><img class="lazyOwl" data-src="assets/owl3.jpg" alt="Lazy Owl Image"></div>
<div class="item"><img class="lazyOwl" data-src="assets/owl5.jpg" alt="Lazy Owl Image"></div>
</div>
尝试过(不工作):
$(document).ready(function() {
$("#owl-demo").owlCarousel({
items : 4,
lazyLoad : true,
navigation : true,
afterAction: function(elem){
$(elem).addClass("curent");
}
});
});
如何在每次幻灯片时添加班级当前项目?
答案 0 :(得分:5)
您可以尝试:
$(document).ready(function () {
var carousel = $("#owl-demo");
carousel.owlCarousel({
items : 4,
lazyLoad : true,
navigation : true,
afterAction: function(el){
//remove class active
this
.$owlItems
.removeClass('active')
//add class active
this
.$owlItems //owl internal $ object containing items
.eq(this.currentItem + 1)
.addClass('active')
}
});
});