-1

I want to find the nearest object to the mouse pointer, on the page. I have the theory that you need to use the array function, but I'm not sure about that. And even if it is so, I do not know which properties I need to ask for.

Lil_VuV
  • 1
  • 3
  • 2
    What's the original problem you're trying to solve? You might need to calculate the distance from elements to the mouse pointer but it depends where those elements are found. – Richie Bendall Oct 09 '22 at 07:30
  • I actually just want to calculate the distance between the mouse pointer and the element, in the problem a point. I have the position of the mouse and the calculation all together and ready, but I still need the x and y position of the point/element. – Lil_VuV Oct 09 '22 at 07:35
  • What is "THE" element ... because your mouse will always be on an element (at the very least, body and or document). So the nearest element will always be at a distance of 0 - You'd have to narrow down the elements you want to check. – Lord-JulianXLII Oct 09 '22 at 08:21

1 Answers1

0

get an array of elements you want to check against. Loop over the array and get the position of each element (with Element.getBoundingClientRect() - https://stackoverflow.com/a/11396681/19529102 ) - calculate distance to curser for each element.

This is the general outline of what I would suggest you try to solve your problem.

Lord-JulianXLII
  • 1,031
  • 1
  • 6
  • 16