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

236
Views
Update pointer-event (scroll, hover, etc.) without mouse movement?

Given two overlapping divs a and b: Changing the "pointer-events" property of a (top div) to "none" will not allow mouse event passthrough to div b (below). The change only takes effect whenever the curser is moved a bit.

How can one make this change be instant, without the user having to move the mouse?

Steps for problem replication using a hover effect:

  1. Open the Codepen
  2. Reload the page
  3. Immediatly place cursor on the red box and do not move the mouse
  4. After 3 seconds the changes take place and the red box will turn purple. But until the mouse moves a bit there will be no update on the css hover of the blue box below.

HTML:

<div class="a"></div>
<div class="b"></div>

CSS:

.a {
  top: 0;
  position: absolute;
  height: 30px;
  width: 30px;
  background: red;
  z-index: 1;
}

.b {
  top: 0;
  position: absolute;
  height: 50px;
  width: 50px;
  background: blue;
}

.b:hover {
  background: green;
}

JS:

delay(3000).then(() => {
  let a  = document.getElementsByClassName("a")[0];
  a.style["pointer-events"] = "none"; // < this updating is the problem
  a.style["background"] = "rgba(255,0,0,.5)"; // purely visual
});

// delay function
function delay(time) {
    return new Promise(resolve => setTimeout(resolve, time));
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To achieve this you want the browser to rerender the scene. There's plenty of ways of doing this – adding or removing elements, for example.

An example is bellow – I've added a div "c" which does nothing, but after you change the pointer-events on "a", I call a setTimeout (without milliseconds, so it's the very next frame) when the background is set, and the display for "c" is set to none. This makes the whole scene redraw and you get the hover value on "b" that you want.

delay(3000).then(() => {
  let a  = document.getElementsByClassName("a")[0];
  a.style["pointer-events"] = "none"; // < this updating is the problem
  
  // this is just to show that it could be any div that you do do this to
  let c  = document.getElementsByClassName("c")[0];
  setTimeout(() => {
    a.style["background"] = "rgba(255,0,0,.5)"; // purely visual
    c.style.display = "none";
  });
});

// delay function
function delay(time) {
    return new Promise(resolve => setTimeout(resolve, time));
}
.a {
  top: 0;
  position: absolute;
  height: 30px;
  width: 30px;
  background: red;
  z-index: 1;
}

.b {
  top: 0;
  position: absolute;
  height: 50px;
  width: 50px;
  background: blue;
}

.b:hover {
  background: green;
}
<div class="a"></div>
<div class="b"></div>

<div class="c"></div>

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!