简体   繁体   English

猫头鹰旋转木马不会自动播放

[英]Owl Carousel Won't Autoplay

I'm using the Owl Carousel on my site.我在我的网站上使用 Owl Carousel。 According to their documentation, this piece of JavaScript should work:根据他们的文档,这段 JavaScript 应该可以工作:

<script>
$("#intro").owlCarousel({

// Most important owl features

//Autoplay
autoPlay : 5000,
stopOnHover : false
)}
</script>

But for some reason it will not autoplay.但由于某种原因,它不会自动播放。 Here is the HTML of the slider:这是滑块的 HTML:

<div id="intro" class="owl-carousel">
    <div class="item first">
      <div class="container">
        <div class="row">
          <div class="carousel-caption-left colour-white">
            <h2>Title Text</h2>
            <h1>Sub title text here.</h1>
            <p>If you like you can even add a sentence or two here.</p>
          </div>
        </div>
      </div>
      <div class="overlay-bg"></div>
    </div>
    <div class="item second">
      <div class="container">
        <div class="carousel-caption-left colour-white">
          <h2>Title Text</h2>
          <h1>Sub title text here.</h1>
          <p>If you like you can even add a sentence or two here.</p>
        </div>
      </div>
      <div class="overlay-bg"></div>
    </div>
    <div class="item third">
      <div class="container">
        <div class="carousel-caption-left colour-white">
          <h2>Title Text</h2>
          <h1>Sub title text here.</h1>
          <p>If you like you can even add a sentence or two here.</p>
        </div>
      </div>
      <div class="overlay-bg"></div>
    </div>
</div>

Yes, its a typing error.是的,是打字错误。

Write

autoPlay自动播放

not不是

autoplay自动播放

The autoplay-plugin code defines the variable as "autoPlay". autoplay-plugin 代码将变量定义为“autoPlay”。

You are may be on the wrong owl's doc version.您可能使用了错误的 owl 文档版本。

autoPlay is for 1st version

autoplay is for 2nd version

Changing autoplay to autoPlay alone did not work for me.单独将自动播放更改为自动播放对我不起作用。 What did the trick was to add autoplaySpeed and autoplayTimeout properties and set them to the same value, like this:诀窍是添加 autoplaySpeed 和 autoplayTimeout 属性并将它们设置为相同的值,如下所示:

$(document).ready(function(){
    var owl = $(".owl-carousel");
    owl.owlCarousel({
        items: 1,
        autoplay: true,
        autoPlaySpeed: 5000,
        autoPlayTimeout: 5000,
        autoplayHoverPause: true
    });
});

Here's a working demo: JS Bin这是一个工作演示: JS Bin

More info about this can be found here: https://github.com/smashingboxes/OwlCarousel2/issues/234可以在此处找到有关此的更多信息: https : //github.com/smashingboxes/OwlCarousel2/issues/234

添加这个

owl.trigger('owl.play',6000);

You should set both autoplay and autoplayTimeout properties.您应该同时设置autoplayautoplayTimeout属性。 I used this code, and it works for me:我使用了这段代码,它对我有用:

$('.owl-carousel').owlCarousel({
                autoplay: true,
                autoplayTimeout: 5000,
                navigation: false,
                margin: 10,
                responsive: {
                    0: {
                        items: 1
                    },
                    600: {
                        items: 2
                    },
                    1000: {
                        items: 2
                    }
                }
            })

This code should work for you这段代码应该适合你

$("#intro").owlCarousel ({

        slideSpeed : 800,
        autoPlay: 6000,
        items : 1,
        stopOnHover : true,
        itemsDesktop : [1199,1],
        itemsDesktopSmall : [979,1],
        itemsTablet :   [768,1],
      });

With version 2.3.4, you need the to add the owl.autoplay.js plugin.对于 2.3.4 版,您需要添加 owl.autoplay.js 插件。 Then do the following然后执行以下操作

var owl = $('.owl-carousel');
owl.owlCarousel({
   items:1, //how many items you want to display
    loop:true,
    margin:10,
    autoplay:true,
    autoplayTimeout:10000,
    autoplayHoverPause:true
});

Just a Typing Error,只是打字错误,

<script>
$("#intro").owlCarousel({

// Most important owl features

//Autoplay
autoPlay : 5000,
stopOnHover : false
)} ----- TYPO
</script>

It should be-它应该是-

<script>
$("#intro").owlCarousel({

// Most important owl features

//Autoplay
autoPlay : 5000,
stopOnHover : false
}) ----- Correct
</script>

Your Javascript should be你的 Javascript 应该是

<script>
$("#intro").owlCarousel({

// Most important owl features

//Autoplay
autoplay: false,
autoplayTimeout: 5000,
autoplayHoverPause: true
)}
</script>

In my case autoPlay not working but autoplay is working fine在我的情况下,将autoPlay没有工作,但自动播放的是做工精细

I only used this我只用过这个

<script src="plugins/owlcarousel/owl.carousel.js"></script>

no owl.autoplay.js is need it & my owl carousel version is @version 2.0.0不需要owl.autoplay.js & 我的owl carousel 版本是@version 2.0.0

hope this thing help you :)希望这件事对你有帮助:)

If you using v1.3.3 then use following property如果您使用 v1.3.3,则使用以下属性

autoPlay : 5000

Or using latest version then use following property或者使用最新版本然后使用以下属性

autoPlay : true

Setting autoPlay: true didn't work for me.设置autoPlay: true对我不起作用。 But on setting autoPlay: 5000 it worked.但是在设置autoPlay: 5000它起作用了。

Owl Carousel version matters a lot, as of now ( 2nd Aug 2020 ) the version is 2.3.4 and the right options for autoplay are: Owl Carousel 版本很重要,截至目前( 2020 年 8 月 2 日),版本为2.3.4 ,自动播放的正确选项是:

$(".owl-carousel").owlCarousel({
    autoplay : true,
    autoplayTimeout: 3000,//Autoplay interval timeout.
    loop:true,//Infinity loop. Duplicate last and first items to get loop illusion.
    items:1 //The number of items you want to see on the screen.
});

Read more Owl configurations阅读更多猫头鹰配置

  1. First, you need to call the owl.autoplay.js.首先,您需要调用 owl.autoplay.js。

  2. this code works for me : owl.trigger('play.owl.autoplay',[1000]);这段代码对我有用:owl.trigger('play.owl.autoplay',[1000]);

I had the same problem and couln't find the solution.我遇到了同样的问题,找不到解决方案。 Finally I realized, that with owlcarousel ver.最后我意识到,使用 owlcarousel ver。 2.3.4 I have to include not only owl.carousel.js, but owl.autoplay.js file too. 2.3.4 我不仅要包含owl.carousel.js,还要包含owl.autoplay.js 文件。

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

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