Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

364
Vistas
document mouseover & mouseout firing multiple times - should just fire once

I need to fire two events. One when the cursor enters the document and when he leaves the document. Right now i have a problem that the events also fire when i use the cursor inside the document, you can see this in the console of my fiddle.

How is it possible to just fire the events when i enter and leave the document?

let cursor = document.getElementById('cursor');

function onMousEnter() {
    cursor.classList.add('is-active');
    console.log("Enter!");
}

function onMouseLeave() {
    cursor.classList.remove('is-active');
    console.log("Out!");
}

document.addEventListener('mouseover', onMousEnter);;
document.addEventListener('mouseout', onMouseLeave);

const onMouseMove = (e) => {
    cursor.style.left = e.pageX + 'px';
    cursor.style.top = e.pageY + 'px';  
}

document.addEventListener('mousemove', onMouseMove);

https://jsfiddle.net/k81zbdmj/1/

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

  1. Use mouseenter instead of mouseover.
  2. Use mouseleave instead of mouseout.

The difference between those is that mouseenter and mouseleave don't bubble. So whenever you move your cursor over or out of a child, those won't trigger the event.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda