Skip to content

Instantly share code, notes, and snippets.

@rfletcher
Created January 18, 2011 21:22
Show Gist options
  • Save rfletcher/785178 to your computer and use it in GitHub Desktop.
Save rfletcher/785178 to your computer and use it in GitHub Desktop.
getMousePos = function( e ) {
return ( e.pageX || e.pageY ) ? {
x: e.pageX,
y: e.pageY
} : ( e.clientX || e.clientY ) ? {
x: e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
y: e.clientY + document.body.scrollTop + document.documentElement.scrollTop
} : null;
},
getLinkPos = function( a ) {
var obj = a, left = 0, top = 0;
if( ! obj.offsetParent ) {
return false;
}
do {
left += obj.offsetLeft;
top += obj.offsetTop;
} while( obj = obj.offsetParent );
return { x: left, y: top };
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment