Can someone please explain how to get mousecoordinates in javascript without jQuery | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can someone please explain how to get mousecoordinates in javascript without jQuery

I want to make particles/objects that follows your mouse

16th Feb 2017, 8:24 PM
Jesse
Jesse - avatar
3 Answers
16th Feb 2017, 9:55 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
Capture mouse move event of the body tag, and you'll get the mouse position coordinates into the event object passed to the callback function: window.onload = function() { document.body.onmousemove = function(evt) { var x = evt.clientX; var y = evt.clientY; console.log(x,y); } } For finger/gesture handling, you need to look at 'touch' events, which provides similar event and properties to read the coordinates of finger(s)...
17th Feb 2017, 2:10 PM
visph
visph - avatar
+ 1
Thanks visph
17th Feb 2017, 2:33 PM
Jesse
Jesse - avatar