触摸屏设备上的 HTML5 拖放 API

发布于 2024-09-12 07:48:00 字数 263 浏览 6 评论 0原文

我只是想知道用于拖放的 HTML5 API 是否包含对触摸屏显示的支持。

我正在考虑 iPhone,但我知道它还不支持。我想知道苹果是否正在追赶,以支持 Safari 移动设备上的 HTML5 拖放,但我也想也许 HTML5 API 对此不够强大,但我对此非常怀疑。

在标准触摸屏笔记本电脑平板电脑或类似设备上怎么样,我没有,所以我无法测试,但我想包含支持,因为据我所知,表格界面只是取代了鼠标控制,所以,就浏览器而言,最终用户实际上只是使用鼠标。

有什么想法吗?

I was just wondering if the HTML5 API for Drag and Drop included support for touch screen displays.

I was thinking of iPhone, but I know this isn't supported yet. I was wondering if that is just catching up on the part of Apple, to support HTML5 drag and drop on Safari mobile, but I also was thinking maybe the HTML5 API wasn't powerful enough for this, but I highly doubt that.

How about on a standard touch screen laptop tablet or the like, I don't have one so I can't test but I would imagine that support is included because, as far as I know, that table interface just replaces mouse control, so, as far as the browser is concerned, the end-user is really just using a mouse.

Any thoughts?

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

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

发布评论

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

评论(3

煮茶煮酒煮时光 2024-09-19 07:48:00

有一些本机 HTML5 事件适用于 WebKit(Chrome 和 Safari)...仅限移动版本。
这些事件的名称是 touchstart、touchmove、touchend、touchcancel

通过触摸重新定位元素的示例是:

$(document).bind("touchstart", function(e) {
e.preventDefault();
var orig = e.originalEvent;
var x = orig.changedTouches[0].pageX;
var y = orig.changedTouches[0].pageY;

$("#element").css({top: y, left: x});
});

更多信息:https://developer.apple.com/documentation/webkitjs/touchevent

顺便说一句,我更喜欢使用 webkit-transform (CSS 属性),因为它具有更好的性能。

There are some native HTML5 Events that works in WebKit (Chrome & Safari) ... only mobile versions.
The name of these events are touchstart, touchmove, touchend, touchcancel

An example to reposition an element with touch is:

$(document).bind("touchstart", function(e) {
e.preventDefault();
var orig = e.originalEvent;
var x = orig.changedTouches[0].pageX;
var y = orig.changedTouches[0].pageY;

$("#element").css({top: y, left: x});
});

More information: https://developer.apple.com/documentation/webkitjs/touchevent

BTW I prefer to work with webkit-transform (CSS properties) 'cause it has a better performance.

倒带 2024-09-19 07:48:00

旧线程,但由于我已经有了一些经验,但它仍然是一个问题,我会尝试一下......

触摸和拖/放并不能真正很好地结合在一起。考虑到对于拖放,您有一个隐含的鼠标按下 =>鼠标移动=>鼠标松开事件序列。在触摸环境中,您不仅拥有标准的 touchstart、touchmove 和 touchend 事件,而且还拥有在各种平台上具有特定含义的实际手势。这些手势是触摸事件、其顺序和时间的组合。

那么如何使用触摸来拖动元素呢?通过捕获touchstart和touchmove?不会。由于胖手指问题,几乎每个触摸事件都有 touchstart 和 touchmove。您也可以有两个触摸启动,偶尔只有一个触摸移动,屏幕很脏。

捕获 touchstart 然后等待查看用户是否移动了一定距离怎么样?不,问题在于,当用户将手指移动 15 像素(或任何距离)并且没有任何反应时,用户会看到“故障”,然后元素突然捕捉到他的手指位置。正常的反应是抬起手指,在这种情况下,手指会落下,这是错误的答案。

最后,尝试开发一个界面,其中一些元素是固定的,而其他元素可以(但不是必须),可拖动是试图将桌面环境适应触摸设备。这些范式不适合。

最好查看各种触摸框架并使用内置手势。

Old thread but since I've got some experience and it is still a problem I'll give it a shot...

Touch and drag/drop do not really play nicely together. Consider that for drag and drop you have an implied mouse-down => mouse-move => mouse-up sequence of events. In a touch environment you have not only the standard touchstart, touchmove and touchend events but you also have actual gestures that have specific meanings on varous platforms. These gestures are combinations of touch events, their order and their timing.

So how would you drag an element using touch? By capturing the touchstart and touchmove? No. Due to the fat-finger problem, almost every touch event has both a touchstart and touchmove. You can also have two touchstarts with only one touchmove occasionally with a dirty screen.

How about capturing touchstart and then waiting to see if the user has moved a certain distance? Nope, the problem there is that the user will see the 'glitch' when he has moved his finger 15 pixels (or whatever distance) and nothing happens and then the element suddently snaps to his finger position. The normal reaction is to lift the finger, which in this scenario would initiate a drop, the wrong answer.

In the end, trying to develop an interface where some elements are stationary and others can, but don't have to be, draggable is trying to fit a desktop environment into a touch device. The paradigms do not fit.

Better to look at the various touch frameworks and use the built-in gestures.

岁月蹉跎了容颜 2024-09-19 07:48:00

遇到同样的问题,这里有一些免费解决方案:

http://touchpunch.furf .com/

https://www.createjs.com/demos/easeljs/draganddrop

Having the same problem, here are a couple of free solutions:

http://touchpunch.furf.com/

https://www.createjs.com/demos/easeljs/draganddrop

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