I am looking for a way to repeat a mouseover action until the user moves away from the target. A mouseover invokes a function once, I am looking for a way to keep doing the
//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);});
You'll 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);
})