获取目标幻灯片项目[Owl Carousel 2]

时间:2018-03-02 15:17:05

标签: owl-carousel owl-carousel-2

我需要根据控制箭头或滑动来获取目标幻灯片项目(上一个或下一个)。

var slider = $('.owl-carousel');
slider.owlCarousel({
   loop: true,
   nav: true,
   items: 1,
   smartSpeed: 600
});

slider.on('change.owl.carousel', function(e) {
   console.log($('.owl-item.active').html());
   // I'm getting html of current slide, but not target slide
});

1 个答案:

答案 0 :(得分:0)

slider.on('changed.owl.carousel', function(e) { // Action, when a carousel has changed
    var target_index = e.property.value; // Index of target slide 
    if($.isNumeric(target_index)) { // if we swipe or clicking controls arrows (or dots) - we got numeric value, but on resize target_index is object, not a number. isNumeric need to prevent wrong value
        $('.owl-item').eq(target_index).html(); // Getting target slide HTML
    }
});