Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

mousemove事件 鼠标不动也会不停触发,妖孽啊!

我想写一段防呆小动画(用户5秒不操作,就会触发动画效果)

    document.body.addEventListener('mousemove', function() {
        clearTimeout(this.tid);
        this.tid = setTimeout(function(){
            console.log('防呆动画');
        }, 5000);
    });

但是这个段动画永远不会执行,我发现即使鼠标不移动也会不停触发移动事件!!!

   //你们试试看,即使不移动鼠标也会不停触发
   document.body.addEventListener('mousemove', function() {
    console.log('move...');
   }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

亲手实践了,并没有问题~


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...