Emerson Emerson - 1 month ago 7
Javascript Question

How to get the correct event.pageX from ondragend

Try this code snippet:

window.ondragend = function(event){
console.log(event.pageX)
}
window.onmouseup = function(event){
console.log(event.pageX)
}


click on a location on a page and then drag an element to the same location. In a maximised window both (at least in Chrome on Windows) pageX' will be the same.
If you minimize the window to fill, say, the right half of the screen, the ondragend will report a different pageX value.


  1. Why does this behaviour happen?

  2. How do I get the correct pageX value from ondragend? Ondragend does not send a mouseup simultaneously, so I can't use that.


Answer

This behaviour has been fixed in the latest versions of Chrome.