How to detect when mousemove has stopped

前端 未结 3 896
悲&欢浪女
悲&欢浪女 2020-12-16 11:57

How is it possible to detect with an eventListener when mousemove has finished?

document.AddEventListener(\'mousemove\', startInteractionTimer,          


        
3条回答
  •  别那么骄傲
    2020-12-16 12:48

    You could try setting/clearing a timeout solely to detect the end of moving the mouse...

    var x;
    document.addEventListener('mousemove', function() { 
        if (x) clearTimeout(x); 
        x = setTimeout(startInteractionTimer, 200); 
    }, false);
    

    How long you want to wait is up to you. I don't know how long you want to say is "the end of a mousemove"

    Example: http://jsfiddle.net/jeffshaver/ZjHD6/

提交回复
热议问题