2010-12-06 3 views
0
function ganttChart(gContainerID) { 

    this.gContainer = document.getElementById(gContainerID); 
    this.gCurrentMouseX; 
    this.gCurrentMouseY; 

    this.gAttatchMove = function(self) { 

     self.gContainer.onmousemove = function() { 


      if (self.gIsDraggingBar) { 

       self.gUpdateMousePos(); 
       self.gBarBeingDragged.style.left = (self.gBarStartX - (self.gMouseStartX - self.gCurrentMouseX)) + "px"; 
      } 

     }; 

     self.gContainer.onmouseup = function() { 
      self.gIsDraggingBar = false; 
     }; 

    } 
    var self = this; 
    this.gAttatchMove(self); 

    // Update mouse coords 
    this.gUpdateMousePos = function(evt) { 
     if (window.event) { 
      this.gCurrentMouseX = event.x; 
      this.gCurrentMouseY = event.y; 
     } 
     else { 
      this.gCurrentMouseX = evt.x; 
      this.gCurrentMouseY = evt.y; 
     } 
    } 

に動作しますこれは、Chromeで正常に動作しますが、FFがエラーをスローします。Javascriptの 'EVTは未定義である' はクローム

evt is undefined

答えて

1

あなたはthis.gUpdateMousePos()mousemoveイベントを渡す必要があります:

self.gContainer.onmousemove = function(evt) { 
    if (self.gIsDraggingBar) { 
     self.gUpdateMousePos(evt); 
     // And the rest follows here 
    } 
}; 

IEは現在のイベントをwindow.eventでのみ提供します。 Firefoxは、イベントハンドラ関数に渡されたパラメータ(これは渡されていないため、エラーです)を介してのみそれを供給します。 ChromeとSafariの両方で動作します(したがって、Chromeではエラーは発生しません)。