我试图检测Owl Carousel何时准备好进行操作,以便可以向其中添加内容。下面的脚本启动轮播,但是初始化事件永远不会触发。

<script type="text/javascript">
    jQuery(document).ready(function () {
        var owl = jQuery("#owl-example");
        owl.on('initialized.owl.carousel', function(e) {
              alert('hi');
        }).owlCarousel({
            navigation: true,
            goToFirstSpeed: 2000,
            singleItem: false,
            transitionStyle: "fade",
            items:<?=$_productCollection->getPageSize()?>,
            lazyLoad: true,
            autoWidth:true,
            scrollPerPage:true,
            mouseDrag:false,
            touchDrag: false,
            startPosition: "zero",
            navigationText: [
                "<strong>&lt;</strong>", //this equates to "<"
                "<strong>&gt;</strong>" //this equates to ">"
            ]
        });
        ;
    });

</script>

最佳答案

在初始化Owl Carousel之前必须附加 initialize.owl.carousel initialized.owl.carousel 事件

检查文档https://owlcarousel2.github.io/OwlCarousel2/docs/api-events.html的此链接

10-05 20:38
查看更多