此代码只是允许在屏幕上拖动正方形。我用Adobe build构建它。我无法弄清楚为什么它不适用于移动平台(android和ios)。在网页上正常工作。手机拖动不能在移动平台上工作
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Draggable - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="phonegap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script>
#draggable {
height: 150px;
padding: 0.5em;
width: 150px;
border: 1px solid black;
background-color: #ddd;
}
</script>
<link rel="stylesheet" href="css/style.css">
<script>
$(document).ready(function() {
// are we running in native app or in a browser?
window.isphone = false;
if(document.URL.indexOf("http://") === -1
&& document.URL.indexOf("https://") === -1) {
window.isphone = true;
}
if(window.isphone) {
document.addEventListener("deviceready", onDeviceReady, false);
} else {
onDeviceReady();
}
});
function onDeviceReady() {
// phonegap ready
init();
$("#draggable").draggable();
$("#msg").prepend("starting<br/>");
}
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";
$("#msg").prepend("touchstart<br/>");
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();
}
</script>
</head>
<body>
<div id="draggable" class="ui-widget-content">
<p>Drag me around</p>
</div>
<div id="msg">
</div>
</body>
</html>
该代码是基于一个基本jQuery UI的例子,我在从各种其他示例的DeviceReady和TouchHandler代码拉动。 我做的似乎没有工作。我错过了什么吗?
当你说“在网页上正常工作”时,你的意思是在手机上呢? – jcesarmobile 2014-12-19 09:49:16
它可以在手机或触摸屏笔记本电脑上的浏览器中使用。 – eyn 2014-12-19 10:29:49
我能够在telerik平台上构建一个可运行的应用程序。仍然无法获得Adobe平台来构建工作应用程序。 – eyn 2014-12-20 08:12:30