Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda