javascript get y position of element code example
Example 1: how to get x y position of an element
function getOffset(el) {
const rect = el.getBoundingClientRect();
return {
left: rect.left + window.scrollX,
top: rect.top + window.scrollY
};
}
Example 2: js get element by X Y
// get the element at a certain (x, y) position
var element = document.elementFromPoint(x, y);
// for a list of elements
var elements = document.elementsFromPoint(x, y);
.