I have the following code which will allowed a user running iOS to move a <div>
with the class .drag
around on the page. This works fine when there is one istance of .drag
, but fails to work when there are two instances of it. Is it possible to have the code find all of the <div>
's, then allow them to be draggable?
var drag = $(".drag")[0];
xPos = drag.offsetWidth / 2;
yPos = drag.offsetHeight / 2;
drag.addEventListener("touchmove", function() {
event.preventDefault();
$(this).css({
'left' : event.targetTouches[0].pageX - xPos + 'px',
'top' : event.targetTouches[0].pageY - yPos + 'px'
});
});