在移动设备上拖放 HTML

发布于 2024-09-08 06:17:03 字数 304 浏览 2 评论 0原文

当您使用JavaScript向网页添加拖放功能(例如jQuery UI可拖放)时,如何在通过移动设备上的浏览器查看时使其发挥作用 - 在移动设备上,触摸屏的拖动操作会被拦截手机用于滚动页面等?

欢迎所有解决方案...我最初的想法是:

  1. 为移动设备提供一个按钮,可以“举起”要拖动的项目,然后让他们单击要放置项目的区域。

  2. 编写一个为移动设备执行此操作的应用程序,而不是尝试让网页在它们上运行!

    编写一个为移动设备执行此操作的应用程序,而
  3. 请您提出建议和意见。

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:

  1. 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.

  2. Write an app that does this for mobile devices rather then try and get the web page to work on them!

  3. Your suggestions and comments please.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

浅语花开 2024-09-15 06:17:03

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/

没有心的人 2024-09-15 06:17:03

有一个 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.

网名女生简单气质 2024-09-15 06:17:03

我需要创建一个适用于桌面、移动设备、平板电脑(包括 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

过潦 2024-09-15 06:17:03

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

虚拟世界 2024-09-15 06:17:03

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.

我的鱼塘能养鲲 2024-09-15 06:17:03

您不妨尝试 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).

旧瑾黎汐 2024-09-15 06:17:03

Jquery Touch Punch 很棒,但它的作用是禁用可拖动 div 上的所有控件,因此为了防止这种情况,您必须更改行...(在撰写本文时 - 第 75 行)

更改

if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])){

为读取

if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0]) || event.originalEvent.target.localName === 'textarea'
        || event.originalEvent.target.localName === 'input' || event.originalEvent.target.localName === 'button' || event.originalEvent.target.localName === 'li'
        || event.originalEvent.target.localName === 'a'
        || event.originalEvent.target.localName === 'select' || event.originalEvent.target.localName === 'img') {

添加尽可能多的或您想要“解锁”的每个元素

希望对某人有帮助

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

if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])){

to read

if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0]) || event.originalEvent.target.localName === 'textarea'
        || event.originalEvent.target.localName === 'input' || event.originalEvent.target.localName === 'button' || event.originalEvent.target.localName === 'li'
        || event.originalEvent.target.localName === 'a'
        || event.originalEvent.target.localName === 'select' || event.originalEvent.target.localName === 'img') {

add as many ors as you want for each of the elements you want to 'unlock'

Hope that helps someone

终陌 2024-09-15 06:17:03

这是我的解决方案:

$(el).on('touchstart', function(e) {
    var link = $(e.target.parentNode).closest('a')  
    if(link.length > 0) {
        window.location.href = link.attr('href');
    }
});

here is my solution:

$(el).on('touchstart', function(e) {
    var link = $(e.target.parentNode).closest('a')  
    if(link.length > 0) {
        window.location.href = link.attr('href');
    }
});
清醇 2024-09-15 06:17:03

对于 vue 3,有 https://github.com/SortableJS/vue.draggable.next< /a>

对于 vue 2,它是 https://github.com/SortableJS/Vue.Draggable

后者你可以这样使用:

<draggable v-model="myArray" group="people" @start="drag=true" @end="drag=false">
   <div v-for="element in myArray" :key="element.id">{{element.name}}</div>
</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:

<draggable v-model="myArray" group="people" @start="drag=true" @end="drag=false">
   <div v-for="element in myArray" :key="element.id">{{element.name}}</div>
</draggable>

These are based on sortable.js

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文