I am trying to bind a mousemove event to the body. My attempts so far:
$('html, body').mousemove(function(event){...});
$('html, body')[0].onmousemove= function(event){...};
$('body').bind('mousemove', function(event){...});
document.onmousemove = function(event){...};
document.getElementsByTagName('body')[0].onmousemove = function(event){...};
EDIT:
window.onmousemove = function(event){...}; // doesn't work either
EDIT2: I need the whole body to be responsive, and not only nested elements.
All of these worked, but none did in IE.
How can I solve this?
I am trying to bind a mousemove event to the body. My attempts so far:
$('html, body').mousemove(function(event){...});
$('html, body')[0].onmousemove= function(event){...};
$('body').bind('mousemove', function(event){...});
document.onmousemove = function(event){...};
document.getElementsByTagName('body')[0].onmousemove = function(event){...};
EDIT:
window.onmousemove = function(event){...}; // doesn't work either
EDIT2: I need the whole body to be responsive, and not only nested elements.
All of these worked, but none did in IE.
How can I solve this?
Share Improve this question edited Nov 7, 2011 at 15:35 arik asked Nov 7, 2011 at 15:11 arikarik 29.4k36 gold badges104 silver badges160 bronze badges 5-
Have you already tried:
window.onmousemove = ...
? – Rob W Commented Nov 7, 2011 at 15:13 -
The version of IE is 9. And I am currently trying it with
window.onmousemove
(not the local puter, takes some time) – arik Commented Nov 7, 2011 at 15:20 - 1 If you bind it on the body (for whatever reason) does that body actually have a size? I'm taking a wield guess here, but could it be that your body consists of only very small height, and you're maybe expecting the visible window to be the body? – Yoshi Commented Nov 7, 2011 at 15:21
- Sime Vidas: no, it doesn't (?! – strange…) Yoshi: Well yes, I do mean the visible area of the body, but the body has sufficient dimensions, because there are quite a few elements within. – arik Commented Nov 7, 2011 at 15:25
- @Sime Vidas, once again: sorry, now I see what it does. However, I need the whole body to be listening, and not only that text element within. – arik Commented Nov 7, 2011 at 15:27
3 Answers
Reset to default 6You don't want it in the body because body is not necessarily the full page.
$( document ).mousemove( function () {
});
jsfiddle: http://jsfiddle/uDfPj/
Alternatively without jQuery:
document.documentElement.onmousemove = function(){};
I doubt whether the onMouseMove event is associated with the body tag. Can you try it on the window tag? I haven't tried that though.
try it with the document instead. here's a great sample page that shows it working
http://www.quirksmode/dom/events/tests/mousemove.html
and a patibility table: http://www.quirksmode/dom/events/mousemove.html