EaselJs canvas dragstart事件不冒泡到父级 [英] EaselJs canvas dragstart event not bubbling to parent

查看:1111
本文介绍了EaselJs canvas dragstart事件不冒泡到父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些canvas元素,需要可拖动。 (不是canvas元素内的元素,我的意思是实际的canvas DOM节点)

I have a number of canvas elements, which need to be draggable. (not elements within the canvas element, i mean the actual canvas DOM node)

代码如下

<div class="top-parent" draggable="true">
  <div class="inner-parent">
     <canvas></canvas>
  </div>
</div>

如果我只有一个没有使用createjs初始化的常规canvas元素, 'm工作正常(我相信它工作离开html5 dragstart事件)。如果我使用 new createjs.Stage(canvas); 拖放功能不工作,似乎dragstart事件不是冒泡,或者甚至不是

If I just have a regular canvas element which hasn't been initialized with createjs the drag drop library i'm working works fine (I believe it works off the html5 dragstart event). If I use new createjs.Stage(canvas); the drag and drop functionality doesn't work, it appears that the dragstart event is not bubbling up, or perhaps not even being registered.

我试过 stage.enableDOMEvents = true; 这看起来不工作 - 我猜因为它应该是默认选项,但我想我会尝试。

I tried stage.enableDOMEvents = true; this doesn't appear to work - which i guess makes sense because it should be the default option but I thought I would try anyway.

推荐答案

EaselJS阶段实例调用 preventDefault()默认情况下,本机触摸/鼠标事件,以防止画布被选中(并得到一个丑陋的选择高亮)。请尝试使用以下命令禁用此功能: myStage.preventSelection = false;

EaselJS Stage instances call preventDefault() on native touch/mouse events by default, to prevent the canvas from being selected (and getting an ugly selection highlight). Try disabling this functionality by using: myStage.preventSelection = false;. That should let those events progress normally, which may allow your drag and drop library to function.

如果你不在阶段使用鼠标事件,那么这些事件会正常进行,这可能会让你的拖放库起作用。 在所有(例如DisplayObject实例与click,mouseDown等处理程序),您可以使用以下命令从Stage DOM事件中完全取消订阅: myStage.enableDOMEvents(false); 。请注意, enableDOMEvents 是一个方法,而您尝试将其用作示例中的属性。

If you are not using mouse events in the Stage at all (ex. DisplayObject instances with click, mouseDown, etc handlers), you can completely unsubscribe the Stage from the DOM events by using: myStage.enableDOMEvents(false);. Note that enableDOMEvents is a method, whereas you are trying to use it as a property in your example.

这篇关于EaselJs canvas dragstart事件不冒泡到父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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