• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

122
Vistas
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));
}
almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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>

almost 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda