Get Mouse Position in JavaScript ('x' and 'y') - JavaScript Tutorial For Beginners

preview_player
Показать описание
Source code on CodePen:

Through using the MouseEvent object, you are able to access the 'x' and 'y' properties, giving you the position of the mouse when that event fired off.

In this video we look at using the 'mousemove' event on the Window object, allowing us to constantly update the x and y coordinates in the browser as the mouse moves across.

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
Рекомендации по теме
Комментарии
Автор

This is so short and precise yet so helpful, thanks a lot.

acupofsoda
Автор

I have been looking for this soooo easy thanks awesome video

bigjimtrucker
Автор

Love these JS videos, keep them coming 👍

lu-vuongle
Автор

This video is AWESOME!! Very informative!

wergler
Автор

Short, but Precise and Crisp. That's the beauty. Thumbs Up and Kudos. Sending you Good Karma.

Kodeispoetry
Автор

Very well explained. Thank you so much!!

happyarish
Автор

Helpful as I am trying to learn mouse trails thank you for the video

DriveandThrive
Автор

Hi, nice video, actually i'm struggling to find a way to detect mouse coordinates while moving faster without lapse. Because i'm trying to do a pixel art drawing canvas and when im holding the mouse to draw lines if I move slow it works perfectly, but if I move the mouse faster many gaps in the line appear.

likyepetti
Автор

Thank you, brother. I have learned from you.

santokhan_
Автор

Very useful script code. Thanks a lot, sir.

_REcon_
Автор

How do we put these values in JavaScript code to move the mouse to this point?

billfeliciano
Автор

Hi, I'm a real beginner and I want to know how I can assign the X and Y coordinates of the mouse to a variable. But the video was great! =)

NekoTheCatTheSlapper
Автор

Mine's not outputting to console any numbers. It's literally printing the phrase "x: $ { e.x } | y: $ { e.y }"

JolanXBL
Автор

is it possible to create something who can indicate the mouse position but in a screen of a certain resolution I can choose

Alice.
Автор

i want to change background color through mousemove and divide my window screen into two part that take different color...how this will possible?

aroshuabdulrehman
Автор

what is a mouse listener coordinate in javascript

calibr
Автор

How would you return the x and y mouse positions to save in a var?

mechang
Автор

I saw the atom editor being used and understood the entire video without even watching it :)

chromefirefox
Автор

This code doesn't appear to work. It works in CodePen, but when I copied the code into VSCode, on Live Server it shows nothing for x and y and throws a 404 error when I open console. when I run it locally it doesn't throw the 404 error, but still still shows nothing.

sallylauper
Автор

Use console.log(e.screenX, e.screenY);

gregarotar