M
M
Maxim Chernykh2020-04-03 22:22:22
JavaScript
Maxim Chernykh, 2020-04-03 22:22:22

How to run autoplay on hover in owl carousel?

owl has autoplayHoverPause, but I need the opposite, so that autoplay is enabled on hover, but not in the normal state.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-04-04
@myskif

$owl.on('mouseenter mouseleave', function(e) {
  $(this).data('owl.carousel').options.autoplay = e.type === 'mouseenter';
  $(this).trigger('refresh.owl.carousel');
});

or
$owl.on('mouseenter mouseleave', function(e) {
  $(this).trigger(({
    mouseenter: 'play',
    mouseleave: 'stop',
  })[e.type] + '.owl.autoplay');
});

UPD. https://jsfiddle.net/hx1bo0yu/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question