• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

111
Views
Drag position issue with event touch move on touch screen

I have implemented drag and drop with html/JavaScript. It works well with mouse drag but having issue with touch screen. while dragging item on touch screen it's position is not correct either it goes up or down from the touch point. Thanks in advance!

var _left = _touch.clientX;
var _top = _touch.clientY;
_touch.target.style.left = _left + 'px';
_touch.target.style.top = _top + 'px';
almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The issue has been resolved. The fix is as below:

var droppable = document.elementFromPoint(_touch.clientX, _touch.clientY);
var _left = _touch.clientX - droppable.getBoundingClientRect().left;
var _top = _touch.clientY - droppable.getBoundingClientRect().top;
_touch.target.style.left = _left + 'px';
_touch.target.style.top = _top + 'px';

I am getting the droppable container's left and top and subtracting it from draggable item.

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error