Gazler
Gazler

Reputation: 84150

Continuous mouseover

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.

Upvotes: 5

Views: 3603

Answers (2)

czarchaic
czarchaic

Reputation: 6318

//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);});

Upvotes: 0

David Hellsing
David Hellsing

Reputation: 108500

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);
})

Upvotes: 7

Related Questions