拖放在phonegap-android中

Ami*_*oda 1 javascript android cordova

我正在尝试使用phonegap-android拖放图像.

当我在mozilla firefox浏览器中运行代码然后代码运行很好,我能够拖动任何图像,但当我在phonegap android 2.1update中运行该代码,然后我无法拖动它,甚至无法点击它.

任何人都可以告诉我什么是错的. http://www.devarticles.com/c/a/JavaScript/Building-DragandDrop-DIVs-Developing-a-Basic-Script/ 我用来拖放

plzz帮我解决..

Thnks

小智 10

亲爱的都在你的HTML中使用它.它没有运行,因为在浏览器中工作的功能是根据鼠标运动模式.你需要做的就是改变手机的触摸模式然后它工作正常......

   $( 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();
   }
Run Code Online (Sandbox Code Playgroud)