jQuery 如何让 jQueryUI 拖放与触摸设备一起使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13940421/
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-26 13:06:38  来源:igfitidea点击:

How to get jQueryUI drag\drop working with touch devices

jqueryjquery-uijquery-ui-draggablejquery-ui-droppable

提问by Brian

This is one situation where I hope someone replies to tell me I'm an idiot. But I continue to be amazed that jQueryUI drag\drop doesn't work with touch devices. I have not tested them all but I have tried iphone\ipad\android 2, 3&4 over the last year and nothing. Just tried the latest version on a new Android. Still nothing. Don't believe me, just visit the demo page on a mobile device and try to use the drag\drop examples. Nothing.

在这种情况下,我希望有人回复告诉我我是个白痴。但我仍然感到惊讶的是 jQueryUI 拖放操作不适用于触摸设备。我没有对它们进行过全部测试,但我在去年尝试了 iphone\ipad\android 2、3 和 4,但一无所获。刚刚在新的 Android 上尝试了最新版本。依然没有。不相信我,只需在移动设备上访问演示页面并尝试使用拖放示例。没有。

Is there a technical problem or core incompatibility in play here? A fix so easy that its not worth writing about? Do jQuery devs not use mobile devices? I have seen "fixes" posted here and there around Stack Overflow but they are all "hacks" and all the ones I've tried don't work.

这里是否存在技术问题或核心不兼容问题?修复如此简单以至于不值得写?jQuery 开发人员不使用移动设备吗?我在 Stack Overflow 到处都看到了“修复”,但它们都是“黑客”,我尝试过的所有方法都不起作用。

I'm perplexed. Can someone shed some light on this issue?

我很困惑。有人可以对这个问题有所了解吗?

回答by forivall

If you just want your current jQuery UI code to work with touch events, you can use the jQuery UI Touch Punchmonkey patch.

如果您只是想让当前的 jQuery UI 代码处理触摸事件,则可以使用jQuery UI Touch Punch猴子补丁。

The only "technical problem or core incompatibility" is that jQuery UI (1.x)only listens for mouse events, not touch events (See @ScottGonzales's response for the historical reason). jQuery touch punch, above, makes that change. You can even try some of the jQuery UI examples on that page, and they work. Generally, using Touch Punch is the currently accepted solution.

唯一的“技术问题或核心不兼容”是 jQuery UI (1.x)仅侦听鼠标事件,而不侦听触摸事件(有关历史原因,请参阅 @ScottGonzales 的响应)。上面的 jQuery touch Punch 实现了这一改变。您甚至可以尝试该页面上的一些 jQuery UI 示例,它们都有效。通常,使用 Touch Punch 是目前公认的解决方案。

回答by Scott González

There's a long history behind why jQuery UI doesn't support touch devices, but it boils down to the fact that Touch Event was a non-standard WebKit-specific implementation. At the time, the future looked dreary. Apple held patents that nobody wanted to go near; as a result, Mozilla implemented their own touch event system with streams which never caught on. It wasn't clear what Microsoft and Opera would do. Paul Bakaus (the creator of jQuery UI) wanted to land iPhone support 4 years ago. I wanted to wait for an official standard.

jQuery UI 不支持触​​摸设备的原因由来已久,但归结为触摸事件是一个非标准的 WebKit 特定实现。那个时候,前途一片黯淡。苹果拥有无人想接近的专利;因此,Mozilla 使用从未流行的流实现了他们自己的触摸事件系统。目前尚不清楚微软和 Opera 会做什么。Paul Bakaus(jQuery UI 的创造者)在 4 年前就想获得 iPhone 支持。我想等待官方标准。

Time passed, Mozilla abandoned their touch events and Microsoft implemented their own pointer events system. The W3C formed a Working Group to standardize Touch Events and investigate the Apple patents. The Touch Events Working Group has published a recommendation and disbanded. Microsoft eventually submitted a proposal to standardize Pointer Events and there is now a W3C Pointer Events Working Group.

时间过去了,Mozilla 放弃了他们的触摸事件,微软实现了他们自己的指针事件系统。W3C 成立了一个工作组来标准化触摸事件并调查 Apple 专利。触摸事件工作组已发布建议并解散。Microsoft 最终提交了标准化指针事件的提案,现在有一个 W3C 指针事件工作组。

We're currently working on a device-agnostic rewriteof all jQuery UI interactions which will be part of jQuery UI 2.0. Until then, you can use jQuery UI Touch Punch.

我们目前正在对所有 jQuery UI 交互进行与设备无关的重写,这将成为 jQuery UI 2.0 的一部分。在此之前,您可以使用jQuery UI Touch Punch

Earlier this year, I wrote about some of the history around Touch Events and why Pointer Events provide a better future. You can read about it on the jQuery blog.

今年早些时候,我写了一些关于触摸事件的历史以及为什么指针事件提供了更好的未来。您可以在jQuery 博客上阅读它。

回答by Jason Whitted

Check out jQTouch

查看jQTouch

It's a jQuery plugin that helps bridge the event gaps between desktop and touch devices.

它是一个 jQuery 插件,有助于弥合桌面和触摸设备之间的事件差距。