Javascript onscroll and mouse position

Posted by EddyR on Stack Overflow See other posts from Stack Overflow or by EddyR
Published on 2010-04-10T09:07:03Z Indexed on 2010/04/10 9:13 UTC
Read the original article Hit count: 533

I have a script that runs a addEventListener for onmousemove and onscroll on the document body to get the cursor position. A onmousemove event works fine (client + scroll), however when a onscroll event occurs clientX/Y seems to inherit scrollTop/Left values instead (only scroll). Is there a way around this?

clickDocument = (document.documentElement != undefined && document.documentElement.clientHeight != 0) ? document.documentElement : document.body;

var posx = 0;
var posy = 0;
if (e.pageX || e.pageY)     {
    posx = e.pageX;
    posy = e.pageY;
}
else if (e.clientX || e.clientY)    {
    posx = e.clientX;
    posy = e.clientY;
}

var scrollx = window.pageXOffset == undefined ? clickDocument.scrollLeft : window.pageXOffset;
var scrolly = window.pageYOffset == undefined ? clickDocument.scrollTop : window.pageYOffset;

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about onscroll