猫头鹰旋转木马改变不起作用

时间:2016-08-30 00:57:09

标签: javascript jquery owl-carousel owl-carousel-2

我似乎无法让owl carousel onchange功能解锁。这是相关代码的片段,任何想法?

HTML:

<div id="my-carousel" class="owl-carousel owl-theme">
    <div class="owl-item"><img alt="" src="pic1"/></div>
    <div class="owl-item"><img alt="" src="pic2" /></div>
</div>

JS:

var my = $('#my-carousel');
my.owlCarousel({
    autoPlay: true,
    autoplaySpeed: 4000,
    loop: true,
    slideSpeed: 300,
    paginationSpeed: 400,
    items: 1,
    margin: 2
});
my.on('changed.owl.carousel', function(e) {
    console.log("test");
});

1 个答案:

答案 0 :(得分:6)

autoplay应全部为小写,并且请注意,没有slideSpeedpaginationSpeed选项。

这是一个工作版本:

&#13;
&#13;
var owl;
$(document).ready(function(){
  owl = $(".owl-carousel").owlCarousel({
    autoplay: true,
    autoplaySpeed: 300,
    loop: true,
    navSpeed: 300,
    items: 1,
    margin: 2
  });
  owl.on('changed.owl.carousel', function(e) {
    console.log("test");
  });
});
&#13;
body {
  margin: 0;
  padding: 0;
}

.owl-carousel .item {
  height: 120px;
  background: #4DC7A0;
  padding: 1rem;
  list-style: none;
  margin: 10px;
  text-align: center;
  color: white;
  font-size: 20px;
  line-height: 120px;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.1.6/assets/owl.carousel.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.1.6/assets/owl.theme.default.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.1.6/owl.carousel.min.js"></script>
<!-- Set up your HTML -->

<div class="owl-carousel">
  <div class="item"> slide1 </div>
  <div class="item"> slide2 </div>
  <div class="item"> slide3 </div>
  <div class="item"> slide4 </div>
  <div class="item"> slide5 </div>
  <div class="item"> slide6 </div>
  <div class="item"> slide7 </div>
  <div class="item"> slide8 </div>
  <div class="item"> slide9 </div>
</div>
&#13;
&#13;
&#13;