0
How to add Event handler in Javascript
Hello guys hope you all are doing well so I have a question is there any event listener function in JavaScript so we can track if mouse is like 10 pixels away from our target element and we want to do that event
3 ответов
0
Make a listener for your mouse movement (onmousemove) and in that function calculate the desired distance. if it was equal to 10px call your final function.
0
mouse coordinates are stored inside the mouse event objects passed as argument to event listener functions registered with addEventListener...
object coordinates are accessible with getBoundingClientRect...
however, you must take attention to coordinates relative to screen or relative to page (and if needed add scroll amount to coordinates ;))
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
0
Thanks brother