JavaScript mousemove Event

The mousemove event fires repeatedly while the mouse pointer moves over an element. The original plus2net demo is preserved below: movement changes the box color, and moving out changes it again.

Bring the mouse inside this box.
Move around, then move outside it.
const box = document.getElementById('moveBox');
box.addEventListener('mousemove', () => {
  box.style.background = '#f06080';
});
box.addEventListener('mouseout', () => {
  box.style.background = '#f0f000';
});

Complete HTML and JavaScript Source

<div id="moveBox">
  Bring the mouse inside this box. Move around, then move outside it.
</div>
<script>
const moveBox = document.getElementById('moveBox');
moveBox.addEventListener('mousemove', () => {
  moveBox.style.background = '#f06080';
});
moveBox.addEventListener('mouseout', () => {
  moveBox.style.background = '#f0f000';
});
</script>
Table of Contents

mousemove Syntax Top ↑

element.addEventListener('mousemove', (event) => {
  console.log(event.clientX, event.clientY);
});

mousemove Can Fire Very Often Top ↑

A handler may run many times during a single pointer movement. Keep the work inside it small. Expensive layout calculations, network calls or large DOM updates should not run on every movement without throttling or another control strategy.

Using mouseout with mousemove Top ↑

The live example uses mouseout to show when the pointer leaves the demo region. For many hover interfaces, mouseenter/mouseleave can be easier to reason about because they do not react to movement between descendants in the same way as mouseover/mouseout.

Event Handling onMouseOver and onMouseOut




Subscribe to our YouTube Channel here



plus2net.com







prasanth

01-12-2012

hai I am trying to get the bottom shadow for the textbox... please suggest



✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer