Created
July 27, 2014 09:07
-
-
Save hehongwei44/2732365bd42baa491ef8 to your computer and use it in GitHub Desktop.
获取鼠标位置的几个通用的函数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*两个通用函数,用于获取鼠标相对于整个页面的当前位置*/ | |
function getX(e) { | |
e = e || window.event; | |
return e.pageX || e.clientX + document.body.scrollLeft; | |
} | |
function getY(e) { | |
e = e || window.event; | |
return e.pageY || e.clientY + document.body.scrollTop; | |
} | |
/*两个获取鼠标相对于当前元素位置的函数*/ | |
function getElementX(e) { | |
return (e && e.layerX) || window.event.offsetX; | |
} | |
function getElementY(e) { | |
return (e && e.layerY) || window.event.offsetY; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment