2014-05-11 87 views
1

我想设计一个使用Phonegap,JQuery UI,JQuery手机的应用程序,我想拖放但我不知道为什么我的代码在手机上无法工作。它在浏览器上正常工作,但是当我在移动设备上运行时,它无法正常工作。jquery ui拖放不工作在手机

这里是我的代码

HTML代码:

<div class="mathheader" align="center" id="container"> 
<span id="a1" class="cartridge" ><img src="img/app2.png"/></span> 
    <span id="a2" class="cartridge"><img src="img/app2.png" /></span> 
    <span id="a3" class="cartridge"><img src="img/app2.png" /></span> 
     <span id="a4" class="cartridge" ><img src="img/app2.png" /></span> 
     <span id="a5" class="cartridge" ><img src="img/app2.png" /></span> 

<table width="100%" border="1" cellspacing="0" cellpadding="5"> 
<tr bgcolor="#F2F2F2"> 
<td width="50%" align="center" class="x" > 
<p><b>coulm1</b></p> 
</td> 
<td width="50%" align="center" class="x"> 
<p><b>coulm2</b></p> 
</td> 
    </tr> 
    <tr> 
    <td width="50%" align="center" id="Td1" class="y" background="img/1.png">  
    </td> 
    <td width="50%" align="center" id="Td2" class="y" background="img/4.png"> 
    </td> 
    </tr> 
    </ table> 

我需要删除此表中所列:

现在我用DARG和一滴类这里是javascript代码: 我使用jquery ui

$(function() { 
     $(".cartridge").draggable({ 
      cursor: 'move', 
      helper: 'clone', 
      revert: 'invalid', 

     }); 

     $(".y").droppable({ 
      accept: '.cartridge', 
      drop: function (event, ui) { 
       $(ui.draggable).appendTo(this); 
       checkwinner(); 
      } 
     }); 

    }); 

它适用于浏览器,但在移动设备上。 谢谢

回答

6

我建议图书馆是https://github.com/yeco/jquery-ui-touch-punch,这个您拖放从jQuery UI的应该在触摸的工作图谋

您可以使用此代码,我使用,它也转换鼠标事件到触摸,它的工作原理是魔法。

function touchHandler(event) { 
    var touch = event.changedTouches[0]; 

    var simulatedEvent = document.createEvent("MouseEvent"); 
     simulatedEvent.initMouseEvent({ 
     touchstart: "mousedown", 
     touchmove: "mousemove", 
     touchend: "mouseup" 
    }[event.type], true, true, window, 1, 
     touch.screenX, touch.screenY, 
     touch.clientX, touch.clientY, false, 
     false, false, false, 0, null); 

    touch.target.dispatchEvent(simulatedEvent); 
    event.preventDefault(); 
} 

function init() { 
    document.addEventListener("touchstart", touchHandler, true); 
    document.addEventListener("touchmove", touchHandler, true); 
    document.addEventListener("touchend", touchHandler, true); 
    document.addEventListener("touchcancel", touchHandler, true); 
} 

并在您的document.ready中调用init()函数。

+0

感谢您的帮助 –

0

移动浏览器未列在JQuery UI browser support的列表中。看看this SO question,它可能会帮助您在移动设备上进行拖放实施。

+0

是的我认为问题是,功能不解雇谢谢你的帮助 –

+0

谢谢你的帮助 –