javascript 在 Createjs / Easeljs 中使用触摸事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17166619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 07:20:31  来源:igfitidea点击:

Using touch events with Createjs / Easeljs

javascriptcanvaseaseljscreatejs

提问by Cod1ngFree

I'm trying to use touch events with Createjs / Easeljs objects. For example, I'm trying to attach a touchstart and touchmove event using addEventListener.

我正在尝试将触摸事件与 Createjs / Easeljs 对象一起使用。例如,我正在尝试使用 addEventListener 附加 touchstart 和 touchmove 事件。

Touchstart and mousedown seems to work: I'm using a browser and a touch device to test it and it seems to work in both cases.

Touchstart 和 mousedown 似乎有效:我使用浏览器和触摸设备来测试它,它似乎在两种情况下都有效。

However, mousemove and touchmove doesn't seem to work. I though it was because I removed the stopPropagation and preventDefault methods, but I saw that Lanny McNie wrote that there is no need to do it in CreateJS 1.

但是, mousemove 和 touchmove 似乎不起作用。我虽然是因为我删除了 stopPropagation 和 preventDefault 方法,但我看到 Lanny McNie 写道,没有必要在 CreateJS 1 中这样做。

I can't figure out why it doesn't work.

我无法弄清楚为什么它不起作用。

This is my code: http://pastebin.com/pqxWLNKG

这是我的代码:http: //pastebin.com/pqxWLNKG

Regards.

问候。

回答by Lanny

You can use the Touch class included with EaselJS to enable multi-touch - which translate into normal EaselJS mousedown/mousemove events. Check out the DragAndDrop demo: http://www.createjs.com/demos/easeljs/draganddrop

您可以使用包含在 EaselJS 中的 Touch 类来启用多点触控——这会转化为正常的 EaselJS mousedown/mousemove 事件。查看 DragAndDrop 演示:http://www.createjs.com/demos/easeljs/draganddrop

createjs.Touch.enable(stage);

Cheers.

干杯。