无法获得鼠标移动事件

时间:2014-10-16 08:28:38

标签: javascript javascript-events google-closure-library

我正在使用谷歌闭包库并注册点击和鼠标移动事件。我得到了点击事件,但鼠标移动事件没有到来。这适用于Chrome浏览器,在Firefox中获得相同的事件

<canvas id='canvas1'  width="512px" height="512px" style='top:0px;right:0px;'  > </canvas>

MyTest.virtualCanvas = function(){
    this.destCanvas = document.getElementById('canvas1');
    this.destCtx = this.destCanvas.getContext('2d');


    this.getCallBackFn = this.highContrastFn.bind(this);
    this.mouseMoveBackFn = this.mouseMoveCB.bind(this);

    goog.events.listen(this.destCanvas, goog.events.EventType.CLICK, this.getCallBackFn);
    goog.events.listen(this.destCanvas, goog.events.EventType.MOUSEMOVE, this.mouseMoveBackFn);


};



MyTest.virtualCanvas.prototype.mouseMoveCB = function(evt){
        var x = evt.offsetX;
        var y = evt.offsetY;

}

MyTest.virtualCanvas.prototype.highContrastFn = function(evt){
    var x = evt.offsetX;
    var y = evt.offsetY;

}

1 个答案:

答案 0 :(得分:0)

我不确定为什么上面没有工作。但是,如果我使用谷歌闭包的绑定方法功能,它的工作原理

goog.events.listen(this.destCanvas, goog.events.EventType.MOUSEMOVE,goog.bind(this.mouseMoveCB, this) )