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

84
Visualizações
How do i find where the button is clicked so that I can position something over there?

I want the popup or modal or toast to appear right where the button in clicked in react. But I was unable to find anything on this. Anything I could find was something like,it appeared in the center or the top or something predefined I guess still not right where the the button was clicked. How should approach this?

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

0

https://reactjs.org/docs/events.html#mouse-events

The MouseEvent parameter on the onClick callback contains the x and y coordinates of the click.

const handleClick = (mouseEvent) => {
    console.log(`x = ${mouseEvent.clientX}, y = ${mouseEvent.clientY}`)
}

React provides 3 different coordinates client, page, and screen the example above makes use of the client coordinates. You can read more about their differences in the MDN Web Docs

about 4 years ago · Juan Pablo Isaza Relatório

0

const box = document.querySelector('#box');

box.addEventListener('click', function(event) {
    console.log(`Horizontal: ${clientX}, Vertical: ${clientY}`);
    // Take Position Current onClick
});

You can set top by clientY, left by clientX from event listener

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