1

我正在创建一个 WebGL 画布,并且正在尝试使用 onmousemove 片段来为影片剪辑按钮创建一个翻转。

首先,我将按钮的翻转状态设置为不可见,如下所示:

this.YesHOT.setVisible(false);

然后我使用 onmousemove 函数打开它,使其在按钮上方时可见,如下所示:

canvas.onmousemove = function(e) { 
    var boundingRect = this.Yes.getBounds(this);
    if(isMouseOverSymbol(e.offsetX, e.offsetY, boundingRect)) {    
        this.YesHOT.setVisible(true);
    }
}.bind(this);

//Function to check whether the specified point lies within the rect.
function isMouseOverSymbol(pointX, pointY, rect) {
    if(rect.left <= pointX && pointX <= rect.left + rect.width)
        if(rect.top <= pointY && pointY <= rect.top + rect.height)
            return true;
    return false;
}

这行得通,但是翻转状态保持可见并且不会关闭。如何让它重新关闭?

4

1 回答 1

0

你从来没有真正this.YesHOT.setVisible(false)打过电话。如果我理解你的意图,代码应该是这样的:

canvas.onmousemove = function(e) { 
    var boundingRect = this.Yes.getBounds(this);
    // if mouse cursor is over the "hot" area, show effect. Otherwise hide.
    this.YesHOT.setVisible(isMouseOverSymbol(e.offsetX, e.offsetY, boundingRect));
}.bind(this);

// also hide the effect when mouse completely leaves the canvas
canvas.onmouseleave = function () {
    this.YesHOT.setVisible(false);
}.bind(this);
于 2016-06-18T18:23:39.170 回答