onmousemove continually fires, indefinitely

by timvasil 11/12/2007 12:14:00 AM

I recently decided to hook document.onmousemove and document.onkeypress for idle detection on a web page.  Kind of the right idea, but surprising results. 

Did you know that, at least with IE 7, the onmousemove event continues to fire a couple times per second even when the mouse is not moving?  and even when the browser window doesn't have the focus, so long as the mouse is over the document?  Bizarre. 

There's an easy enough way around this issue:

document.onmousemove = observeMoveActivity;
var g_iOldX;
var g_iOldY;
function observeMoveActivity()
{
    if (event && (event.screenX != g_iOldX || event.screenY != g_iOldY))
    {
        g_iOldX = event.screenX;
        g_iOldY = event.screenY;
        observeActivity();  // do actual work here
    }
}

Tags:

JavaScript

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Search

Calendar

«  May 2012  »
SuMoTuWeThFrSa
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar

Recent comments

Archive