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

102
Visualizações
Send mouseover event to all overlaid elements

Does anyone know how to propagate/trigger the mouseover event to multiple children when they appear overlaid on top of each other? Is it even possible?

I'm trying to get mouseover to be triggered for 2 overlaid elements. I've written a basic example to demonstrate the problem:

example-output

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <style>
    body {
      background-color: black;
    }
    .relative {
      position: relative;
    }
    .child-1,
    .child-2 {
      position: absolute;
      width: 200px;
      height: 200px;
    }
    .child-1 {
      top: 0;
      left: 0;
      background-color: rgba(255, 255, 0, 0.5);
    }
    .child-2 {
      top: 50px;
      left: 50px;
      background-color: rgba(0, 255, 255, 0.5);
    }
  </style>

  <body class="relative">
    <div class="child-1">1</div>
    <div class="child-2">2</div>
  </body>

  <script>
    const child1 = document.querySelector('.child-1');
    const child2 = document.querySelector('.child-2');

    child1.addEventListener('mousemove', () => console.log(1));
    child2.addEventListener('mousemove', () => console.log(2));
  </script>
</html>

Whenever I hover over just child 1, I get a log of 1. When I hover over just child 2, I get a log of 2. That all works. But when I hover over 1 and 2 where they overlap, I only get a log of which ever one is on top, in this case 2 (this can be flipped by adjusting the z-index or order in the DOM).

I found this answer, but changing the z-index or pointer-events: none doesn't help me because I need both the element's event to fire.

about 4 years ago · Juan Pablo Isaza
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