Continuous mouseover

前端 未结 2 1852
无人及你
无人及你 2020-12-21 10:04

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

相关标签:
2条回答
  • 2020-12-21 10:23
    //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 讨论(0)
  • 2020-12-21 10:26

    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);
    })
    
    0 讨论(0)
提交回复
热议问题