在HTML5本机拖动过程中检测keydown/up事件 [英] Detecting keydown/up events during HTML5 native drag

查看:94
本文介绍了在HTML5本机拖动过程中检测keydown/up事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以使用本机HTML5拖动的元素.它具有分配给它的dragstart,drag和dragend事件侦听器.另外,我还将keydown和keyup事件侦听器分配给document.body元素.

I've an element that can be dragged using native HTML5. It has dragstart, drag, and dragend event listeners assigned to it. In addition, I also have keydown and keyup event listeners assigned to document.body element.

当拖动可拖动元素时,ondrag事件将按预期触发.当我按&释放任何键而不拖动任何东西,将触发document.body keydown/up事件.

When dragging the draggable element, ondrag event will fire as expected. When I press & release any key while not dragging anything, document.body keydown/up events will fire.

但是,如果我在执行ondrag时按下/按下,则不会触发document.body按下/按下事件.有什么解决方法/黑客吗?

However, if I keydown/up while performing ondrag, the document.body keydown/up event will not fire. Is there any workaround/hack to this?

推荐答案

回答我自己的问题...来自

Answering my own questions... From Drag Operations - MDN:

对于Dragenter和Dragover事件,dropEffect属性为 初始化为用户正在请求的效果.用户可以 通过按修改键修改所需的效果.虽然 所使用的确切键因平台而异,通常是Shift键和Control键 将用于在复制,移动和链接之间进行切换.

With the dragenter and dragover event, the dropEffect property is initialized to the effect that the user is requesting. The user can modify the desired effect by pressing modifier keys. Although the exact keys used vary by platform, typically the Shift and Control keys would be used to switch between copying, moving and linking.

在HTML5本机拖动中,唯一可以触发任何内容的按键是修饰键.在Mac上,它是选项键和控制键.动作是通过 event.dataTransfer.effectAllowed 捕获的,而不是通过按键或按下事件捕获的.

On HTML5 native drag, the only key press that can trigger anything is the modifier keys. On Mac, it's the option key and the control key. Action is captured via event.dataTransfer.effectAllowed, not keypress or keydown events.

这篇关于在HTML5本机拖动过程中检测keydown/up事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆