Owl Carousel Won't Autoplay

2019-01-12 02:40发布

I'm using the Owl Carousel on my site. According to their documentation, this piece of JavaScript should work:

<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:

<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>

13条回答
可以哭但决不认输i
2楼-- · 2019-01-12 02:58
  1. First, you need to call the owl.autoplay.js.

  2. this code works for me : owl.trigger('play.owl.autoplay',[1000]);

查看更多
老娘就宠你
3楼-- · 2019-01-12 02:59

You are may be on the wrong owl's doc version.

autoPlay is for 1st version

autoplay is for 2nd version
查看更多
小情绪 Triste *
4楼-- · 2019-01-12 03:01

Yes, its a typing error.

Write

autoPlay

not

autoplay

The autoplay-plugin code defines the variable as "autoPlay".

查看更多
走好不送
5楼-- · 2019-01-12 03:01

Your Javascript should be

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

// Most important owl features

//Autoplay
autoplay: false,
autoplayTimeout: 5000,
autoplayHoverPause: true
)}
</script>
查看更多
闹够了就滚
6楼-- · 2019-01-12 03:06

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:

$(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

More info about this can be found here: https://github.com/smashingboxes/OwlCarousel2/issues/234

查看更多
对你真心纯属浪费
7楼-- · 2019-01-12 03:08

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>
查看更多
登录 后发表回答