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
if put 'body' instead of document, doesn't work, why?
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); }); })();
Comments
Post a Comment