javascript 回调事件不起作用 - 使用 Owl Carousel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28355772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 08:51:10  来源:igfitidea点击:

Callback events not working - using Owl Carousel

javascriptjqueryowl-carousel-2

提问by TylersSN

I am trying to detect when Owl Carousel is ready to be manipulated so that I can add content to it. The script below initiates the carousel but the initialized event never triggers.

我试图检测 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>

回答by Husamuddin

initialize.owl.carouseland initialized.owl.carouselevents must be attached before Owl Carousel initialization

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

Check this link of the documentation https://owlcarousel2.github.io/OwlCarousel2/docs/api-events.html

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

回答by Emre K?klü