I'm creating a JS to run the code as if it were slides.
<div class="uk-panel uk-panel-box tm-mandato uk-hidden-small widget_recent_entries">
<div class="uk-width-1-1 uk-width-medium-1-4 uk-overlay-hover">
<div class="tm-imagem uk-height-1-1">
...
</div>
</div>
<div class="uk-width-1-1 uk-width-medium-1-4 uk-overlay-hover">
<div class="tm-imagem uk-height-1-1">
...
</div>
</div>
</div>
I made two JS in an attempt to make the slides pass automatically (every 5s) and stop auto-execution with the mouse hover (it can be in the .tm-command class or in the .uk-overlay- hover). However, both codes run automatically, but they do not stop running when hover is present.
Code 1:
var timer;
function startTimer() {
timer = setInterval(function () {
var noticia = jQuery('.tm-mandato');
var controleActive = noticia.find('.uk-active');
var contadorNoticia = noticia.find('.uk-overlay-hover').length;
var index = controleActive.index();
controleActive.removeClass('uk-active');
if (index < contadorNoticia - 1){
controleActive.next().addClass('uk-active')
} else {
noticia.find('.uk-overlay-hover:first').addClass('uk-active')
}
}, 5000);
}
jQuery(document).ready(function($){
$('tm-mandato .uk-overlay-hover').hover(function (ev) {
clearInterval(timer);
}, function (ev) {
startTimer();
});
});
startTimer();
Code 2
jQuery(document).ready(function($){
var timer = 5000;
$('.tm-mandato > .uk-overlay-hover').mouseenter(function(ev){
clearInterval(timer);
}, setInterval (function(ev){
var noticia = jQuery('.tm-mandato');
var controleActive = noticia.find('.uk-active');
var contadorNoticia = noticia.find('.uk-overlay-hover').length;
var index = controleActive.index();
controleActive.removeClass('uk-active');
if (index < contadorNoticia - 1){
controleActive.next().addClass('uk-active')
} else {
noticia.find('.uk-overlay-hover:first').addClass('uk-active')
}
}, timer));
});
How can I resolve this hover issue?