Continuous navigation

I am looking for a way to repeat the mouse action until the user moves away from the target. Mouseover calls the function once, I'm looking for a way to save the function.

Cheers, Gazler.

+3
source share
2 answers

You need to use setInterval():

var to;
var doStuff = function() {
    console.log('doing stuff...');
};

$('a').hover(function(e) {
    to = window.setInterval(doStuff, 1);
},function(e) {
    window.clearInterval(to);
})
+6
source
//continuous


var timer;

var doStuff=function(quit){

  console.log('doing stuff');

  if (quit!==true){

    timer=setTimeout(doStuff, 100);

  }

  else{

    clearTimeout(timer);

  }

};

$('div#continuous').bind('mouseenter', doStuff).bind('mouseleave', function(){doStuff(true);});
0
source

Source: https://habr.com/ru/post/1725562/


All Articles