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

240
Views
Can't get closest element to drop after drag with elementFromPoint

document.elementFromPoint defines the element before or after which the dragged element should be inserted. When I use this method, it returns the item being dragged, not the one to be defined. Why doesn't it happen and how do I fix the error?

 evt.preventDefault();
 if (!draggedEl) {
   return;
 }
 draggedEl.style.left = `${evt.pageX - draggedEl.offsetWidth / 2}px`;
 draggedEl.style.top = `${evt.pageY - draggedEl.offsetHeight / 2}px`;
 **const closest = document.elementFromPoint(evt.clientX, evt.clientY);**
 const { top } = closest.getBoundingClientRect();
 if (evt.pageY > window.scrollY + top + closest.offsetHeight / 2) {
   // closest.style.paddingBottom = `${draggedElWidth}px`;
 } else {
   // closest.style.paddingTop = `${draggedElWidth}px`;
 }
});

Full code: https://github.com/tati-simonenko/ahj6/blob/master/src/js/taskWidget.js

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!