W
W
Web Lizard2017-10-20 18:04:50
JavaScript
Web Lizard, 2017-10-20 18:04:50

How to make Owl Carousel events work?

Hello.
The task is to perform some actions after the changed event in the Owl slider.
The documentation says that it can be done in this way

var owl = $('.owl-carousel');
owl.owlCarousel();
// Listen to owl events:
owl.on('changed.owl.carousel', function(event) {
    ...
})

And, of course, this method does not work. After all, why write examples in the documentation that work, right?
Anyway. I also found this solution. in the same documentation.
$('.owl-carousel').owlCarousel({
    onDragged: callback
});
function callback(event) {
    ...
}

The result is nothing happens.
That's exactly how I did it all for me.
var slider = $('.autopark-slider');
      slider.owlCarousel({
        pagination: false,
        navigation: true,
        slideSpeed: 444,
        paginationSpeed: 333,
        singleItem: true,
        touchDrag: true,
        autoPlay: false,
        afterAction: afterAction(),
        onDragged: callback,
        navigationText: false
      });

      function callback(event) {
        console.log('Этот консоль лог не срабатывает');
      }
      function afterAction() {
        console.log('А этот срабатывает, но только один раз при запуске слайдера');
      };

Well, that's what I also tried to do, the result is missing.
var slider = $('.autopark-slider');
      slider.owlCarousel({
        pagination: false,
        navigation: true,
        slideSpeed: 444,
        paginationSpeed: 333,
        singleItem: true,
        touchDrag: true,
        autoPlay: false,
        afterAction: afterAction(),
        onDragged: callback,
        navigationText: false
      });

      function callback(event) {
        console.log('Этот консоль лог не срабатывает');
      }
      function afterAction() {
        console.log('А этот срабатывает, но только один раз при запуске слайдера');
      };

      slider.on('changed.owl.carousel', function(event) {
        callback();
      });

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
Web Lizard, 2017-10-20
@Lizard-108

In short, I figured it out myself, this is done through afterMove .

slider.owlCarousel({
        pagination: false,
        navigation: true,
        slideSpeed: 444,
        paginationSpeed: 333,
        singleItem: true,
        touchDrag: true,
        autoPlay: false,
        // afterInit: afterAction(),
        afterMove: callback,
        navigationText: false
      });

The authors of the documentation are m****ki

P
pshj, 2022-04-21
@pshj

You have to do it like this:

var owl = $(".owl-block");
    owl.owlCarousel({
      items: 1,
      autoplay: true,
      dots: true,
      margin: 12,
      loop: true,
      onTranslated: changename,
    });
 function changename(event) {
     console.log(event);
 }

Works on OwlCarousel2 - I just checked it myself)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question