Return to Snippet

Revision: 5148
at February 14, 2008 16:06 by 1man


Initial Code
function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        cursor.x = e.clientX + 
            (document.documentElement.scrollLeft || 
            document.body.scrollLeft) - 
            document.documentElement.clientLeft;
        cursor.y = e.clientY + 
            (document.documentElement.scrollTop || 
            document.body.scrollTop) - 
            document.documentElement.clientTop;
    }
    return cursor;
}

Initial URL
http://ajaxian.com/archives/javascript-tip-cross-browser-cursor-positioning

Initial Description
Nice little snippet i found on Ajaxian, finds the position of the mouse cursor when it is fired.

Initial Title
Cross Browser Cursor Position

Initial Tags

                                

Initial Language
JavaScript