此代碼只是允許在屏幕上拖動正方形。我用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