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

269
Vistas
JavaScript cancel "mouseleave" event on "click"

I'm working on a problem where I'm not able to find a solution. I'm still a beginner though. Here the code:

var navContact = document.getElementsByClassName("nav-l")[0];
var contactForm = document.getElementsByClassName("kontakt")[0];

var navContactMouseEnter = function (e) {
  console.log("mouse entered!");
  navContact.style.paddingLeft = "5vw";
  contactForm.style.transform = "translateX(-25vw)";
}

var navContactMouseLeave = function (e) {
  console.log("mouse left!");
  navContact.style.paddingLeft = "0vw";
  contactForm.style.transform = "translateX(-31vw)";
}

navContact.addEventListener("mouseenter", navContactMouseEnter, true);
navContact.addEventListener("mouseleave", navContactMouseLeave, true);

navContact.addEventListener("click", (e) => {
  e.preventDefault();
  navContact.removeEventListener("mouseleave", navContactMouseLeave, true);
  navContact.style.paddingLeft = "5vw";
  contactForm.style.transform = "translateX(0vw)";
});

I'm trying to get a little slideIn Animation on "mouseenter" but on "click" that element should slideout completely and ignore any "mouseleave" event. There I'm faceing the issues... I'm not able to cancel the "mouseleave" event. That element should only disappear when I click on "X" - but thats no problem.

I'm grateful for any help.

Thanks in advance!

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

0

Ok, after breaking my head for couple more hours I found out, that I also needed to do this:

navContact.removeEventListener("mouseenter", navContactMouseEnter, true);

I also got different styles on the mouseenter-event, which pulled the element back again.

Lesson learned :D

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