Tim*_*Tim 15 html jquery jquery-ui multi-touch jquery-mobile
我使用jQuery,jQuery UI和jQuery mobile为iPhone/iPad构建Web应用程序.现在我创建图像,它们应该是可拖动的,所以我这样做:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Drag - Test</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.css" />
<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"></script>
</head>
<body>
<div>
<div style="width:500px;height:500px;border:1px solid red;">
<img src="http://upload.wikimedia.org/wikipedia/en/thumb/9/9e/JQuery_logo.svg/200px-JQuery_logo.svg.png" class="draggable" alt="jQuery logo" />
<img src="http://upload.wikimedia.org/wikipedia/en/a/ab/Apple-logo.png" class="draggable" alt="Apple Inc. logo" />
</div>
</div>
</body>
<script type="text/javascript">
$(document).ready(function() {
$(".draggable").draggable();
});
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
在这里你可以看到现场的例子:http://jsbin.com/igena4/
问题是,整个页面想要滚动.我在Apple的HTML5示例中搜索并发现这是为了防止页面滚动,以便图像可拖动:
...
onDragStart: function(event) {
// stop page from panning on iPhone/iPad - we're moving a note, not the page
event.preventDefault();
...
}
Run Code Online (Sandbox Code Playgroud)
但问题是对我来说,如何将其包含在我的jQuery中?我从哪里来event?
最好的祝福.
JE4*_*E42 23
试试这个库
https://github.com/furf/jquery-ui-touch-punch
只需按照以下简单步骤在jQuery UI应用程序中启用触摸事件:
在您的页面上包含jQuery和jQuery UI.
Run Code Online (Sandbox Code Playgroud)<script src="http://code.jquery.com/jquery.min.js"></script> <script src="http://code.jquery.com/ui/1.8.17/jquery-ui.min.js"></script>在jQuery UI之后和第一次使用之前包括Touch Punch.
请注意,如果您使用的是jQuery UI的组件,则必须在jquery.ui.mouse.js之后包含Touch Punch,因为Touch Punch会修改其行为.
Run Code Online (Sandbox Code Playgroud)<script src="jquery.ui.touch-punch.min.js"></script>没有3.只需按预期使用jQuery UI,只需轻轻一按即可观看它.
Run Code Online (Sandbox Code Playgroud)<script>$('#widget').draggable();</script>
我找到了一个解决方案,该解决方案适用于iPad和iPhone上的桌面浏览器和iOS Safari:http: //code.google.com/p/jquery-ui-for-ipad-and-iphone/
您只需要下载并集成JavaScript文件即可.