You can use getBoundingClientRect()to get the coordinates of the element when you click the mouse button and move just like that
element.onClick = function() {
element.onmousemove = function() {
var x1 = element.getBoundingClientRect().left,
x2 = x1 + element.getBoundingClientRect().width,
y1 = element.getBoundingClientRect().top,
y2 = element.getBoundingClientRect().height;
}
}
and now you can do whatever you want with these coordinates.
source
share