Mouse Events
Learn how to control mouse events.
We'll cover the following
Mouse events
There’s a number of events that relate to the mouse pointer and its interactions with elements on the page.
Mouse move
Every time the mouse pointer moves, the mousemove
event fires. To see an example of this, we’ll write some code that tells us the coordinates of the mouse pointer whenever it moves.
Let’s add the following event listener in the index.js
file:
document.addEventListener('mousemove', showCoords);
This will call the showCoords
function whenever the mouse pointer moves anywhere on the page. Let’s write that function now:
Get hands-on with 1400+ tech skills courses.