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 function.
Cheers, Gazler.
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 function.
Cheers, Gazler.
Share Improve this question edited Aug 26, 2013 at 9:46 Daniel Daranas 22.6k9 gold badges65 silver badges121 bronze badges asked Dec 13, 2009 at 20:50 GazlerGazler 84.2k18 gold badges284 silver badges245 bronze badges2 Answers
Reset to default 7You'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);
})
//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);});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744253437a4565278.html
评论列表(0条)