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

176
Visualizações
How to set a rectangle on the top center of another rectangle with pure JS

I would like to get the result like this expected. The actual problem is a div will be displayed on the top center of an icon ( behaviour like a tooltip). I have tried the following code:

const iconPosition= this.el.nativeElement.getBoundingClientRect();

const divPosition= this.div.getBoundingClientRect();

let top;
let left;

if (this.placement === 'top') {
  top = iconPosition.top - divPosition.height;
  left = iconPosition.left + (iconPosition.width - divPosition.width) / 2;
} 

The top works fine but I have an issue with the left. It leads me to this result: current

Could someone help? I got stuck for two days now. Any support is greatly appreciated! Thank you all!

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

0

Just as an input: Can it be, that the part: (iconPosition.width - divPosition.width) / 2 is negative? So you are going to move thed upper div to the left instead to the right Math.abs(); might help, but without code......

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