简体   繁体   English

Createjs事件-“ mouseleave”有效,但“ click”无效

[英]Createjs events - “mouseleave” works but “click” doesn't

I'm using nodejs with socket. 我正在使用带有套接字的nodejs。 This is my code on the frontend. 这是我在前端的代码。

let socket = io.connect();

function init() {
    let stage = new createjs.Stage("canvas");
    stage.enableMouseOver(20);
    stage.on("mouseleave", function (event) {
        console.log("mouseleave");
    });
    stage.on("click", function (event) {
        console.log("click");
    });
    stage.update();
}

I see "mouseleave" logging on the console when I move the cursor out of the canvas. 将光标移出画布时,我在控制台上看到“ mouseleave”日志。 But never see "click" when I click. 但是当我单击时再也看不到“单击”。 I also tried "mousedown" but it also doesn't work. 我也尝试过“ mousedown”,但是它也不起作用。

Thanks. 谢谢。

The "click" event only fires when content on the stage is clicked. 仅在单击舞台上的内容时才触发“ click”事件。 The event will bubble up, and be dispatched from the stage. 该事件将起泡,并从舞台上调度。 If you click empty space, there is no event. 如果单击空白区域,则不会发生任何事件。

Instead, use the "stage" mouse events. 而是使用“阶段”鼠标事件。

stage.on("stagemousedown", function (event) {
    console.log("mousedown");
});

stage.on("stagemouseup", function (event) {
    console.log("click");
});

Link to documentation 链接到文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM