如何使用 javascript/jquery 处理 iphone 和 ipad 上的拖动事件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2162454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 23:02:21  来源:igfitidea点击:

How to handle drag events on iphone and ipad with javascript/jquery?

javascriptiphoneipaduiwebview

提问by fmsf

I have a little app that has been under development for some time. My friends and I have been working really hard on this and are near release of the beta version.

我有一个已经开发了一段时间的小应用程序。我和我的朋友一直在为此努力工作,并且即将发布测试版。

I want to give some demos using iPhone and iPad to look cool :p

我想用 iPhone 和 iPad 做一些演示,让它看起来很酷:p

Now my problem is how to handle:

现在我的问题是如何处理:

  • Mouse Down
  • Mouse Up
  • Mouse Leave
  • 鼠标按下
  • 鼠标向上
  • 鼠标离开

The multitouch interface of the iPhone (which I expect is similar to the iPad) handles mouse move on a browser has a scrolling event. One could try to capture the scrolling event and use it to simulate the dragging but I don't even know if it will be doable or if it will only be a hack.

iPhone 的多点触控界面(我希望它类似于 iPad)在浏览器上处理鼠标移动有一个滚动事件。人们可以尝试捕获滚动事件并使用它来模拟拖动,但我什至不知道它是否可行,或者它是否只是一种黑客攻击。

Any one knows of a more robust manner to manage dragging events on the iphone/ipad?

任何人都知道一种更强大的方式来管理 iphone/ipad 上的拖动事件?

采纳答案by kubi

Apple's Developer pages have a lot of good info on handling just these types of issues.

Apple 的 Developer pages 有很多关于处理这些类型问题的好信息。

Handling Events

处理事件

回答by Shamasis Bhattacharya

I was having the same problem and I realized that in the short time-span I had, developing codes to handle raw mouse (down, move and up) events would take time. So, I went ahead and modified the ThreeDumsMedia jQuery.event.drag plugin to make it to work on iPhone.

我遇到了同样的问题,我意识到在我的短时间内,开发代码来处理原始鼠标(向下、移动和向上)事件需要时间。因此,我继续修改了 ThreeDumsMedia jQuery.event.drag 插件,使其能够在 iPhone 上运行。

Get the jQuery.event.drag from http://www.shamasis.net/2011/06/javascript-drag-events-on-iphone-and-other-touch-based-devices/and the 'drag' event would work just fine on iOS devices.

http://www.shamasis.net/2011/06/javascript-drag-events-on-iphone-and-other-touch-based-devices/获取 jQuery.event.drag并且“拖动”事件将起作用在 iOS 设备上就好了。

let me know if this helped.

如果这有帮助,请告诉我。

回答by Mandeep Pasbola

Try this :

尝试这个 :

jquery.event.drag - v 2.2 Three Dub Media - http://threedubmedia.com

jquery.event.drag - v 2.2 三配音媒体 - http://threedubmedia.com

回答by phatmann

If you are using jQuery, then use jquery.ui.mouse.touch.jswith jquery UI 1.9.

如果您使用的是 jQuery,则将jquery.ui.mouse.touch.jsjquery UI 1.9 一起使用