How to reset autoplay timeout when scrolled by user?
Now, when user scroll the carousel manually, it can be scrolled twice: by user + by autoplay.
+1
Probably there is better solution, but this is good enough for me now - though it doesn't handle mobiles (I hope they will rather drag than use the nav functions).
$('.owl-carousel').on('mouseenter', '.owl-dots, .owl-nav', function(e) {
$(this).closest('.owl-carousel').trigger('stop.owl.autoplay');
});
$('.owl-carousel').on('mouseleave', '.owl-dots, .owl-nav', function(e) {
$(this).closest('.owl-carousel').trigger('play.owl.autoplay');
});
This happens with drag on mobile also (autoplay transition can happen just after a drag). I used this to reset autoplay both on drag and navigating with the buttons:
$('.owl-carousel').on('touchstart', 'img', function(e) {
$(this).closest('.owl-carousel').trigger('stop.owl.autoplay');
});
$('.owl-carousel').on('touchend', 'img', function(e) {
$(this).closest('.owl-carousel').trigger('play.owl.autoplay');
});
$('.owl-carousel').on('click', '.owl-dots, .owl-nav', function(e) {
$(this).closest('.owl-carousel').trigger('stop.owl.autoplay');
$(this).closest('.owl-carousel').trigger('play.owl.autoplay');
});
This should be the default behavior I think.
@zcorpan that looks good, but it might need a check if autoplay was enabled for the carousel, and only trigger play.owl.autoplay if it was enabled before.
I couldn't get the touchstart or end to work using the above:- so I opted to use the onDragged Callback :-
```
var owl = $('#myCarousel').owlCarousel({
// other options removed for brevity
onDragged: resetTimeOut
});
function resetTimeOut(e) {
owl.trigger('stop.owl.autoplay');
owl.trigger('play.owl.autoplay');
}
owl.on('click', '.owl-dots, .owl-nav', function(e) {
resetTimeOut();
});
Note: I'm targeting one particular carousel here, but it could easily be updated for a more general deployment.
Most helpful comment
This happens with drag on mobile also (autoplay transition can happen just after a drag). I used this to reset autoplay both on drag and navigating with the buttons:
This should be the default behavior I think.