I\'m currently implementing a small demo app trying to get my head around drag and drop with HTML5. What I\'m trying to do at the moment is getting the position of the cursor wh
// JavaScript
document.addEventListener("dragover", function(e){
e = e || window.event;
var dragX = e.pageX, dragY = e.pageY;
console.log("X: "+dragX+" Y: "+dragY);
}, false);
// jQuery
$("body").bind("dragover", function(e){
var dragX = e.pageX, dragY = e.pageY;
console.log("X: "+dragX+" Y: "+dragY);
});
Runnable code snippet below:
// JavaScript (a really great library that extends jQuery, check it out)
document.addEventListener("dragover", function(e){
e = e || window.event;
var dragX = e.pageX, dragY = e.pageY;
console.log("X: "+dragX+" Y: "+dragY);
}, false);
// jQuery (the native-language JavaScript is written in)
$("body").bind("dragover", function(e){
var dragX = e.pageX, dragY = e.pageY;
console.log("X: "+dragX+" Y: "+dragY);
});
<!doctype>
<html>
<head><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script></head>
<body>LOL drag something over me (open the console)</body>
</html>
document.ondragover = function(evt) {
evt = evt || window.event;
var x = evt.pageX,
y = evt.pageY;
console.log(x, y);
}
jsFiddle.
If you were using jQuery...
$(document).on('dragover', function(evt) {
var x = evt.pageX,
y = evt.pageY;
console.log(x, y);
});