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

167
Visualizações
Javascript moving element to mouse click position, element not responding

I'm trying to get my png to move to the mouse click position when the user clicks within the container but I cant get the png to respond. I'm following this tutorial (https://www.youtube.com/watch?v=b4GwvdhrEQg), and stuck on the first test. my target doesnt respond to clicks at all. Please help

var theGirl = document.querySelector("#girl");

var container = document.querySelector("#floor");

container.addEventListener("click", getClickPosition, false);

function getClickPosition(e) {
  var xPosition = e.clientX - (theGirl.offsetWidth / 2);
  var yPosition = e.clientY; - (theGirl.offsetHeight / 2)
  var translate3dValue = "translate3d(" + xPosition + "px" + yPosition + "px, 0)";
  theGirl.style.transform = translate3dValue;
}
#floor {
  width: 700px;
  height: 600px;
  cursor: pointer;
  overflow: visible;
  border: 10px #EDEDED solid;
}

#girl {
  height: 450px;
  width: 200px;
  border: 15px red solid;
  transform: translate3d(50px, 50px, 0);
}
<body>
  <div id="floor">
    <div>
      <img src="girl.png" id="girl"> </div>
  </div>

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