I want to drag an element named moveMe and drop it anywhere within the window. This code already works on google chrome using a desktop computer. But when i opened this file in an iPad, it is not functioning. I had researched about ontouchstart, ontouchmove and ontouchend and applied it to this code but still it doesn't work. Please help me on how to get this code work on an iPad without using jQuery because iPad is not good at handling jQuery. And if there is a more efficient way to do this.
function init() {
movMeId=document.getElementById("moveMe");
movMeId.style.left="900px";
movMeId.style.top="500px";
}
document.onmousedown=coordinates;
document.onmouseup=mouseup;
function coordinates(e) {
if (!e) {
e = window.event;
}
var sender = (typeof( window.event ) != "undefined" ) ? e.srcElement : e.target;
if (sender.id == "moveMe") {
mouseover=true;
pleft = parseInt(movMeId.style.left);
ptop = parseInt(movMeId.style.top);
xcoor = e.clientX;
ycoor = e.clientY;
document.onmousemove = moveImage;
return false;
}
else {
return false;
}
}
function moveImage(e) {
if (!e) {
e = window.event;}
movMeId.style.left = pleft + e.clientX - xcoor + "px";
movMeId.style.top = ptop + e.clientY - xcoor + "px";
return false;
}
function mouseup(e) {
document.onmousemove=null;
movMeId.style.left="900px";
movMeId.style.top="500px";
}