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

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -