execute Jquery when the mouse stops moving

前端 未结 2 1740
夕颜
夕颜 2021-02-08 06:10

I have a quick script that has a trail follow the cursor:

jQuery(document).ready(function(){
   $(document).mousemove(function(e){
       $(\'.fall\').each(funct         


        
2条回答
  •  故里飘歌
    2021-02-08 06:33

    You add a timeout that fires after one second of inactivity, and clear the timeout if the mouse moves within 1 second etc :

    var timer;
    $(document).on('mousemove', function(e){
       clearTimeout(timer);
    
       timer = setTimeout(function() {
           $('.fall').fadeOut('slow', function() {
               $(this).remove();
           });
       }, 1000);
    });
    

    FIDDLE

    EDIT:

    Here's how I'd do it

    FIDDLE

提交回复
热议问题