I am trying to create javascript to get the X and Y coordinates of a div element. After some attempts, I came up with some numbers, but I'm not sure how to check their exact location (the script returns X as 168 and Y as 258). I am running a script using a screen resolution of 1280 x 800. This script I use to get this result:
function get_x(div) { var getY; var element = document.getElementById("" + div).offsetHeight; var get_center_screen = screen.width / 2; document.getElementById("span_x").innerHTML = element; return getX; } function get_y(div) { var getY; var element = document.getElementById("" + div).offsetWidth; var get_center_screen = screen.height / 2; document.getElementById("span_y").innerHTML = element; return getY; }โ
Now the question. Would it be reasonable to assume that these are the exact coordinates returned by the function, or is it just to just create a little something in this place to see what exactly is happening?
And finally, how can I do this div element? I know that I have to use the mousedown event handler and for a while to keep moving the element, but yes, any tips / hints are much appreciated, my biggest problem is how to get this while the loop is running.
javascript drag-and-drop
Jeffrey klinkhamer
source share