1

I am trying to drag and drop images using phonegap-android.

When i run the code in the mozilla firefox browser then the code runs great and i am able to drag any image but when i run that code in phonegap android 2.1update then i am not able to drag it and even not able to click on it.

Anyone can tell me whats going wrong. http://www.devarticles.com/c/a/JavaScript/Building-DragandDrop-DIVs-Developing-a-Basic-Script/ that i used for drag and drop

plzz help me out..

Thnks

Amit Hooda
  • 2,133
  • 3
  • 23
  • 37

2 Answers2

11

Dear all use this in your html. It is not running because the functions working in browser are according to mouse motion mode. Thing you have to do is change to on touch mode of mobile then it works fine...

   $( init );

 function init() {
  document.addEventListener("touchstart", touchHandler, true);
  document.addEventListener("touchmove", touchHandler, true);
  document.addEventListener("touchend", touchHandler, true);
  document.addEventListener("touchcancel", touchHandler, true);   
  }
  function touchHandler(event)
  {
  var touches = event.changedTouches,
  first = touches[0],
  type = "";
  switch(event.type)
  {
  case "touchstart": type = "mousedown"; break;
  case "touchmove":  type="mousemove"; break;        
  case "touchend":   type="mouseup"; break;
  default: return;
  }
  var simulatedEvent = document.createEvent("MouseEvent");
   simulatedEvent.initMouseEvent(type, true, true, window, 1,
                      first.screenX, first.screenY,
                      first.clientX, first.clientY, false,
                      false, false, false, 0/*left*/, null);
  first.target.dispatchEvent(simulatedEvent); 
  event.preventDefault();
   }
  • i was doing that only,but i solved this by binding touchstart and touchmove together that worked great :) – Amit Hooda Feb 21 '12 at 06:17
  • @ amit in my mob it works fine for drag and drop but the issue is i can drag but for dropping i need to click once again then only its dropping in mobile but browser works fine... – srinivasaraghavan ramji Feb 21 '12 at 06:41
  • @ srinivasaraghavan ramji follow this link ,,,u ll get everythng u need :) http://popdevelop.com/2010/08/touching-the-web/ – Amit Hooda Feb 23 '12 at 07:40
1

Jquery Mobile Drag And Drop

Similar discussion:

Community
  • 1
  • 1
Dmitry F
  • 1,650
  • 1
  • 15
  • 20
  • I tried Jquery mobile drag and drop but it only works on ttl so it doesn't provide drag option ,,but i have completed the task by binding touchstart and touchmove event and for drop i used touchend event and i m done with that :) . Thnks for the reply – Amit Hooda Oct 05 '11 at 06:12