Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!