Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Callback Functions(like afterMove) are not called

The following is a code taken form Owl Carousel's own site. I don't know why the callback functions(here afterMove) are not called! Could anybody get the afterMove function called? For me it's not just afterMove, but none of the callbacks works!

<html>
<head>
  <!-- Owl Carousel -->
  <link rel="stylesheet" href="js/vendors/owl-carousel-2/assets/owl.carousel.min.css">

  <!-- Owl Default Theme -->
  <link rel="stylesheet" href="js/vendors/owl-carousel-2/assets/owl.theme.default.min.css">

  <style type="text/css">
    #owl-demo .item {
        background: #3fbf79;
        padding: 30px 0px;
        margin: 10px;
        color: #FFF;
        border-radius: 3px;
        text-align: center;
    }
  </style>
</head>
<body>
  <div id="owl-demo" class="owl-carousel">
    <div class="item"><h1>0</h1></div>
    <div class="item"><h1>1</h1></div>
    <div class="item"><h1>2</h1></div>
    <div class="item"><h1>3</h1></div>
    <div class="item"><h1>4</h1></div>
    <div class="item"><h1>5</h1></div>
    <div class="item"><h1>6</h1></div>
  </div>

<!-- jQuery -->
<script src="js/jquery/1.9.1/jquery.min.js"></script>
<!-- Owl Carousel -->
<script src="js/vendors/owl-carousel-2/owl.carousel.js"></script>

<script type="text/javascript">
  $(document).ready(function() {

  var owl = $("#owl-demo");
  owl.owlCarousel({
    navigation : true,
    afterMove : afterMove
  });

  function afterMove(){
    alert("Hey!");
  }
});
</script>
</body>
</html>
like image 597
Fighter Jet Avatar asked Dec 01 '25 16:12

Fighter Jet


1 Answers

you need to use new events with .on(), as per mentioned in its docs, as:

var owl = $("#owl-demo");
owl.owlCarousel({
    navigation : true
});
//register `change` event
owl.on('changed.owl.carousel', function(e) {
    alert("changed");
});

Demo :: jsFiddle

like image 159
Sudhir Bastakoti Avatar answered Dec 03 '25 07:12

Sudhir Bastakoti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!