我有一个可以使用原生HTML5拖动的元素.它具有分配给它的dragstart,drag和dragend事件侦听器.另外,我还将keydown和keyup事件侦听器分配给document.body元素.
拖动可拖动元素时,ondrag事件将按预期触发.当我按下&释放任何键而不拖动任何东西,document.body keydown / up事件将触发.
但是,如果我在执行ondrag时keydown / up,则document.body keydown / up事件不会触发.这有什么解决方法/黑客吗?
解决方法:
回答我自己的问题……从Drag Operations – MDN开始:
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捕获操作,而不是keypress或keydown事件.