如何让jquery在移动设备上拖动工作? [英] How to get jquery dragging working on mobile devices?

查看:75
本文介绍了如何让jquery在移动设备上拖动工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个允许用户拖动一些图像的应用程序.它使用jQuery.我正在尝试使其在移动设备上运行(在iPhone上,如果我拖动图像,则它将拖动整个页面).我想使用jquery mobile.这是正确的方法吗?如果是这样,从常规jquery过渡到jquery mobile很容易吗?而且,如果我使用jquery mobile,它还能从桌面上拖动吗?

I have an application where I allow users to drag some images around. It uses jquery. I'm trying to get it working on mobile devices (on the iPhone, if I drag the image then it drags the whole page). I want to use jquery mobile. Is this right way to go? If so, is it pretty easy to transition from regular jquery to jquery mobile? And also, if I use jquery mobile, will it still be draggable from a desktop as well?

谢谢!

推荐答案

我找到了解决此问题的非常简单的方法- jQuery UI触摸打孔.

I found a very simple solution to this problem - jQuery UI Touch Punch.

它可以有效地将触摸事件转换为点击事件,因此您的可拖动代码将如您期望的那样在移动/平板电脑触摸屏上正常工作.

It works by effectively converting touch events into click events, so your draggable code will work as you'd hoped on mobile/tablet touch screens.

要实施,您只需要下载Touch Punch脚本,然后将其包含在HTML中,然后将 添加到您的其他jQuery/jQuery UI中:

To implement, you just need to download the Touch Punch script and then include it in your HTML after your other jQuery / jQuery UI includes:

<script src="scripts/jquery.ui.touch-punch.min.js"></script>

我已经在Android和iOS上进行了测试,并且对我来说是第一次使用,完全没有问题.

I have tested on Android and iOS and it worked first time for me with no issues at all.

这篇关于如何让jquery在移动设备上拖动工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆