简体   繁体   English

猫头鹰轮播2在该部分可见时开始自动播放

[英]owl carousel 2 start autoplay when the section visible

I am working on a project where I want to start the autorun function of owl carousel 2 when i will be in that carousel section. 我正在一个项目中,当我进入该轮播区时,我想启动owl carousel 2的自动运行功能。 Normally the autorun will not run and when i scroll down and hover over the section the autoplay will start. 通常,自动运行不会运行,并且当我向下滚动并悬停在该部分上时,将开始自动播放。 See code --- 见代码-

HTML: HTML:

<div class="header">
    <h1>this is heading section</h1>
</div>
<div class="section">
    <h1>This is section</h1>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries</p>
    <div class="owl-carousel">
        <div><img src="http://placehold.it/550x450"/></div>
        <div><img src="http://placehold.it/550x450"/></div>
        <div><img src="http://placehold.it/550x450"/></div>
        <div><img src="http://placehold.it/550x450"/></div>
        <div><img src="http://placehold.it/550x450"/></div>
        <div><img src="http://placehold.it/550x450"/></div>
        <div><img src="http://placehold.it/550x450"/></div>
        <div><img src="http://placehold.it/550x450"/></div>
        <div><img src="http://placehold.it/550x450"/></div>
    </div>   
</div>

JS: JS:

var owl = $('.owl-carousel');
owl.owlCarousel({
    items: 1,
    center: false,
    loop: true,
    autoplay: false,
    autoplayTimeout: 1000,
    smartSpeed:1000,
    autoplayHoverPause: true
});
$('.section').mouseover(function(e) {
    owl.trigger('play.owl.autoplay', [1000]);
})

See I use mouseover function to active the function , I mean when i mouseover the section the autoplay need to run but it is not working ... please help me out ... 请参阅我使用mouseover功能激活该功能,这意味着当我将鼠标悬停在该部分上时,需要运行自动播放功能,但该功能无法正常工作...请帮助我...

JSFIDDLE DEMO PROJECT HERE JSFIDDLE DEMO项目在这里

So, you need the following. 因此,您需要以下内容。

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

$('.section').on("mouseenter", function(e) {
    owl.trigger('owl.play', 1000);
    //Not owl.trigger('play.owl.autoplay', [1000]);
})

- Demo - - 演示 -

Take a look at the doc since you've either been using an old version/using non-existent params. 由于您一直在使用旧版本/使用不存在的参数,因此请查看文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM