Dragging two elements at once | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 12

Dragging two elements at once

I want some help https://code.sololearn.com/WkJVt3oqrv6I/?ref=app There are two div elements, I want to drag both with two different fingers but when I do this, one div goes on one finger

30th Jan 2020, 3:48 PM
Farhan
Farhan - avatar
5 Answers
+ 8
further to taste's answer error demo (no touches[1] when dragging only blue) : https://code.sololearn.com/WQ6GX0oGI9R5/?ref=app correct way (event delegation) : https://code.sololearn.com/WTUS1utrc7sT/?ref=app Taste How to ensure touches[1] is applied on second finger target? Explicitly, when first finger is blue, and second finger is red.
30th Jan 2020, 3:57 PM
Gordon
Gordon - avatar
+ 8
When using multi fingers on touch, it would create 2 set of e.touches array, e.touches[0] and e.touches[1] You should use touchstart event to detect the e.touches.length, and then use touchmove to track of e.touched[n].x / y.
30th Jan 2020, 4:14 PM
Calviղ
Calviղ - avatar
+ 8
I tried to keep track the touched using touchstart and touchend https://code.sololearn.com/WGv7W9pMfkD3/?ref=app
30th Jan 2020, 4:30 PM
Calviղ
Calviղ - avatar
+ 7
Gordon like this maybe, https://code.sololearn.com/W8RfNlkWVFrk/?ref=app edit: play around with it for a little bit, its not 100% usable.
30th Jan 2020, 4:28 PM
Taste
Taste - avatar
+ 4
use touches[1] for a second finger
30th Jan 2020, 3:53 PM
Taste
Taste - avatar