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

230
Visualizações
Get coordinates of element inside dropdown

I got a dropdown list and want to show some information on hover for each element. I tried something like this, with item being the list elements and infobox being a fixed positioned div providing the information:

item.addEventListener("mouseover", (e) => {
   e.stopPropagation();
   if (e.target === e.currentTarget) {
     dropdownInformation.category_id = selectOptions.category_id[index];
     document.getElementById("infobox").style.left = e.target.getBoundingClientRect().x + "px";
     document.getElementById("infobox").style.top = e.target.getBoundingClientRect().y + "px";
     }
});

How'd I get the correct coordinates of the right border of the list entries?

Dropdown list

(Yes, I did read several other questions regarding that topic on SO)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Okay, this seems to do the trick. I needed to add / subtract the width / height of the parent element and the scrollbar.

item.addEventListener("mouseover", (e) => {
    e.stopPropagation();
    if (e.target === e.currentTarget) {
        dropdownInformation.category_id = selectOptions.category_id[index];
        e.target.style.borderLeft = "2px white solid";
        document.getElementById("infobox").style.left = 
          (e.target.getBoundingClientRect().x +
          e.target.getBoundingClientRect().width + 
          (e.target.parentElement.offsetWidth - 
          e.target.parentElement.clientWidth)) + "px";

        document.getElementById("infobox").style.top = 
          (e.target.getBoundingClientRect().y - 
          (e.target.parentElement.getBoundingClientRect().height / 2)) + "px";
    }
});
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