Answer the question
In order to leave comments, you need to log in
Document.elementFromPoint how to find all elements that occupy a coordinate?
I have such a thing.
Green is the shadow of the block being dragged with the mouse.
I have something like this function, in order to find the DIV from which you need to build this shadow.
document.querySelector('body').addEventListener(
'mousemove',
throttle(function(e) {
let Shadow = document.elementFromPoint(e.x - 2, e.y - 2);
}
Answer the question
In order to leave comments, you need to log in
Found on the Internet.
function getAllElementsFromPoint(x, y) {
var elements = [];
var display = [];
var item = document.elementFromPoint(x, y);
while (item && item !== document.body && item !== window && item !== document && item !== document.documentElement) {
elements.push(item);
display.push(item.style.display);
item.style.display = "none";
item = document.elementFromPoint(x, y);
}
// restore display property
for (var i = 0; i < elements.length; i++) {
elements[i].style.display = display[i];
}
return elements;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question