jquery - Mousemove event working on document but not 'body' -


i trying make div turned-off light , when mouse moves, light turns on.

i done part mouse movement turns light on. @ this fiddle.

jquery code:

$(document).mousemove(function() {     $('div').addclass('glow'); }); 

i have 2 questions it

  1. if put 'body' instead of document, doesn't work, why?

  2. how can detect mouse stop?

1) 'body' works must move mouse on body, doesn't go until bottom of window (yes, body strange , incoherent thing).

2) detect mouse stop, simplest solution use settimeout , define delay :

(function (){     var =0;     var timer;     $('body').mousemove(function() {         cleartimeout(timer);         // 'body' doesn't work instead of document         += 1;         $('p').text(function() {             return 'moved: ' + i;         });         $('div').addclass('glow');         timer = settimeout(function(){$('div').removeclass('glow')}, 2000);     });      })(); 

demonstration


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -