Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!