Owl Carousel不会自动播放

the*_*dog 24 html javascript owl-carousel

我在我的网站上使用猫头鹰旋转木马.根据他们的文档,这段JavaScript应该工作:

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

// Most important owl features

//Autoplay
autoPlay : 5000,
stopOnHover : false
)}
</script>
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,它不会自动播放.这是滑块的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>
Run Code Online (Sandbox Code Playgroud)

Mat*_*lin 70

是的,它打字错误.

自动播放

自动播放

autoplay-plugin代码将变量定义为"autoPlay".

  • 直到看到你的帖子,我才遇到这个问题.我设置了"autoPlay",但实际上将其更改为"autoplay"使它对我有用.奇怪的. (8认同)
  • 版本确实很重要.Owl Carousel 2使用"自动播放".旧版本使用"autoPlay".另外值得注意的是,在版本2中,您必须使用"autoplayTimeout"来设置自动播放功能的速度.在旧版本中,这实际上是由"autoPlay"选项设置的. (3认同)

1ro*_*mat 33

你可能是错误的猫头鹰的doc版本.

autoPlay is for 1st version

autoplay is for 2nd version
Run Code Online (Sandbox Code Playgroud)


Vee*_*ani 13

单独将自动播放更改为autoPlay对我不起作用.诀窍是添加autoplaySpeed和autoplayTimeout属性并将它们设置为相同的值,如下所示:

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

这是一个有效的演示:JS Bin

有关这方面的更多信息,请访问:https://github.com/smashingboxes/OwlCarousel2/issues/234

  • 我可以确认这适用于最新版本! (2认同)

M A*_*fan 6

加上这个

owl.trigger('owl.play',6000);
Run Code Online (Sandbox Code Playgroud)


小智 5

您应该同时设置autoplayautoplayTimeout属性。我使用了这段代码,它对我有用:

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


小智 5

在 2.3.4 版本中,您需要添加 owl.autoplay.js 插件。然后执行以下操作

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
});
Run Code Online (Sandbox Code Playgroud)


Nei*_*eil 3

只是一个打字错误,

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

// Most important owl features

//Autoplay
autoPlay : 5000,
stopOnHover : false
)} ----- TYPO
</script>
Run Code Online (Sandbox Code Playgroud)

它应该是-

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

// Most important owl features

//Autoplay
autoPlay : 5000,
stopOnHover : false
}) ----- Correct
</script>
Run Code Online (Sandbox Code Playgroud)