在移动设备上拖放 HTML
当您使用JavaScript向网页添加拖放功能(例如jQuery UI可拖放)时,如何在通过移动设备上的浏览器查看时使其发挥作用 - 在移动设备上,触摸屏的拖动操作会被拦截手机用于滚动页面等?
欢迎所有解决方案...我最初的想法是:
为移动设备提供一个按钮,可以“举起”要拖动的项目,然后让他们单击要放置项目的区域。
编写一个为移动设备执行此操作的应用程序,而不是尝试让网页在它们上运行!
编写一个为移动设备执行此操作的应用程序,而请您提出建议和意见。
When you add drag and drop to a web page using JavaScript, such as jQuery UI draggable and droppable, how do you get this to work when viewed via a browser on a mobile device - where the touch-screen actions for dragging are intercepted by the phone for scrolling around the page etc?
All solutions welcome... my initial thoughts are:
Have a button for mobile devices that "lifts" the item to be dragged and then get them to click the zone they want to drop the item on.
Write an app that does this for mobile devices rather then try and get the web page to work on them!
Your suggestions and comments please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
jQuery UI Touch Punch 正好解决了这一切。
它是 jQuery UI 的触摸事件支持。基本上,它只是将触摸事件连接回 jQuery UI。
在 iPad、iPhone、Android 和其他支持触摸的移动设备上进行了测试。
我使用了 jQuery UI sortable,它的工作方式就像一个魅力。
http://touchpunch.furf.com/
jQuery UI Touch Punch just solves it all.
It's a Touch Event Support for jQuery UI. Basically, it just wires touch event back to jQuery UI.
Tested on iPad, iPhone, Android and other touch-enabled mobile devices.
I used jQuery UI sortable and it works like a charm.
http://touchpunch.furf.com/
有一个 Polyfill 用于将触摸事件转换为拖放,以便 HTML5 拖放可在移动设备上使用。
该polyfill 由 Bernardo Castilho 在
这是该帖子的演示。
这篇文章还介绍了 Polyfill 设计的几个注意事项。
There is a polyfill for translating touch events to drag-and-drop, such that HTML5 Drag And Drop is utilizable on mobile.
The polyfill was introduced by Bernardo Castilho on this post.
Here's a demo from that post.
The post also presents several considerations of the polyfill design.
我需要创建一个适用于桌面、移动设备、平板电脑(包括 Windows Phone)的拖放 + 旋转。最后一个使事情变得更加复杂(mspointer 与触摸事件)。
解决方案来自伟大的 Greensock 库
它需要一些跳跃才能使同一个对象可拖动并且可旋转,但效果很好
I needed to create a drag and drop + rotation that works on desktop, mobile, tablet including windows phone. The last one made it more complicated (mspointer vs. touch events).
The solution came from The great Greensock library
It took some jumping through hoops to make the same object draggable and rotatable but it works perfectly
Sencha Touch 的测试版具有拖放支持。
您可以参考他们的 DnD 示例。顺便说一句,这只适用于 webkit 浏览器。
将该逻辑改造到网页中可能会很困难。据我了解,它们禁用所有浏览器平移并完全在 JavaScript 中实现平移事件,从而允许正确解释拖放。
更新:原始示例链接已失效,但我找到了这个替代方案:
https://github.com/kostysh/Drag-Drop-example- for-Sencha-Touch
The beta version of Sencha Touch has drag and drop support.
You can refer to their DnD Example. This only works on webkit browsers by the way.
Retrofitting that logic into a web page is probably going to be difficult. As I understand it they disable all browser panning and implement panning events entirely in javascript, allowing correct interpretation of drag and drop.
Update: the original example link is dead, but I found this alternative:
https://github.com/kostysh/Drag-Drop-example-for-Sencha-Touch
Sortable JS 库 与触摸屏兼容,不需要 jQuery。
库大小为 43KB。
官网在视频中表示,这个库的运行速度比 JQuery UI Sortable 更快。
The Sortable JS library is compatible with touch screens and does not require jQuery.
The library size is 43KB.
The official website states in a video that this library is running faster than JQuery UI Sortable.
您不妨尝试 Tim Ruffle 的拖放填充,当然与 Bernardo Castilho 的类似(请参阅@remdevtec 答案)。
只需执行npm install mobile-drag-drop --save(其他可用的安装方法,例如使用bower)
然后,任何依赖于触摸检测的元素界面都应该在移动设备上工作(例如仅拖动一个元素,而不是同时滚动+拖动)。
You might as well give a try to Tim Ruffle's drag-n-drop polyfill, certainly similar to Bernardo Castilho's one (see @remdevtec answer).
Simply do
npm install mobile-drag-drop --save
(other installation methods available, e.g. with bower)Then, any element interface relying on touch detection should work on mobile (e.g. dragging only an element, instead of scrolling + dragging at the same time).
Jquery Touch Punch 很棒,但它的作用是禁用可拖动 div 上的所有控件,因此为了防止这种情况,您必须更改行...(在撰写本文时 - 第 75 行)
更改
为读取
添加尽可能多的或您想要“解锁”的每个元素
希望对某人有帮助
Jquery Touch Punch is great but what it also does is disable all the controls on the draggable div so to prevent this you have to alter the lines... (at the time of writing - line 75)
change
to read
add as many ors as you want for each of the elements you want to 'unlock'
Hope that helps someone
这是我的解决方案:
here is my solution:
对于 vue 3,有 https://github.com/SortableJS/vue.draggable.next< /a>
对于 vue 2,它是 https://github.com/SortableJS/Vue.Draggable
后者你可以这样使用:
这些基于 sortable.js
For vue 3, there is https://github.com/SortableJS/vue.draggable.next
For vue 2, it's https://github.com/SortableJS/Vue.Draggable
The latter you can use like this:
These are based on sortable.js