在发生变更的事件中将类别添加到Owl Carousel项目

时间:2019-03-17 08:04:53

标签: jquery carousel owl-carousel

我使用Owl Carousel,试图在divs居中轮播项目的任一侧添加一个类。选项'center:true'将类'center'应用于中间项。然后,我正在使用changed.owl.carousel事件将“ center”类添加到上一个和下一个div中。事件正在触发,我可以看到控制台日志,但是它没有将类添加到这些相邻的div中。

当我在changed.owl.carousel事件之外运行addclass函数时,它将正确地将这些类添加到div中,但只能添加一次,并且在幻灯片更改时不会重复。

任何人都可以提供解决方案吗?

我已经准备好a jsfiddle which demonstrates the problem

这是我正在尝试的js:

var owl;
jQuery(document).ready(function(){
  owl = $(".owl-carousel").owlCarousel({
    autoPlay: 3000,
    loop: true,
    items: 7,
    margin: 20,
    autoplay: true,
    stagePadding: 50,
    center: true
  });
  owl.on('changed.owl.carousel', function(e) {
    jQuery('.owl-item.center').prev().addClass("center");
    jQuery('.owl-item.center').next().addClass("center");
    console.log("fired!");
  });
});

0 个答案:

没有答案
相关问题