-
-
Save remy/360018 to your computer and use it in GitHub Desktop.
Get element from mouse position
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
var x,y; | |
document.onmousemove = function(e){ | |
e = e || window.event; | |
x = e.clientX; | |
y = e.clientY; | |
}; | |
function elementAtMousePosition() { | |
return document.elementFromPoint(x,y); | |
} |
I'm using clientX on another hack that's currently working in Safari, Opera and Firefox...
Huh?
It works in all these browsers? So maybe they've changed it?
Or does it work only as long as you have not scrolled your page? ;)
It seems as if Chrome has adopted clientX, but I do remember that I needed pageX to satisfy Safari the last time I checked.
Just curious - is it for marbles2 or something?
I have been struggling to figure out how to make elementFromPoint work. I am implementing a drag & drop using hammer.js and I would like to know when the panend event has fired which is the DOM element beneath the target
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
elementFromPoint is not very well known, but really awesome!
However, do remember that Firefox/IE uses clientX/Y while Safari/Opera uses pageX/Y coordinates!
/Jacob