【问题标题】:Fail to get mouse move event获取鼠标移动事件失败
【发布时间】:2014-10-16 08:28:38
【问题描述】:

我正在使用 Google 闭包库并注册点击和鼠标移动事件。我得到了点击事件,但是鼠标移动事件没有出现。这是 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;
                
}

【问题讨论】:

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


    【解决方案1】:

    我不确定为什么上述方法不起作用。但是,如果我使用 google 闭包中的 bind 方法函数,它可以工作

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-22
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多