Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda