【问题标题】:Detecting click on empty part of the stage in easelJs在画架中检测对舞台空白部分的点击
【发布时间】:2014-09-01 01:59:18
【问题描述】:

我在检测到鼠标点击/触摸舞台的空白部分时遇到问题。这是我的设置:

stage = new createjs.Stage(canvas);
stage.addChild(exportRoot);
stage.addEventListener('click', onStageClicked);

function onStageClicked(event) {
  console.log('event.currentTarget: ', event.currentTarget);
  console.log('event.target: ', event.target);
  console.log('event.target.parent: ', event.target.parent);
};

我只有在点击舞台上的某些形状或图像时才能登录控制台,但在点击舞台的实际空白部分时不会登录。如何检测对舞台/画布空白部分的点击?

tnx

卢卡

【问题讨论】:

    标签: javascript easeljs


    【解决方案1】:

    使用“stagemousedown”或“stagemouseup”事件。我从下面的代码中提取了 EaselJS 文档在这里:http://www.createjs.com/tutorials/Mouse%20Interaction/

    stage.on("stagemousedown", function(evt) {
        alert("the canvas was clicked at "+evt.stageX+","+evt.stageY);
    })
    

    【讨论】:

    • Tnx。这是一种有效的解决方法。 :) 这与文档相关,我错过了:对于舞台,就像所有其他显示对象一样,只有当鼠标悬停在不透明像素上时才会收到事件。
    猜你喜欢
    • 1970-01-01
    • 2012-06-21
    • 1970-01-01
    • 2012-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多