2010-12-06 2 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; 
     } 
    } 

이 크롬에서 잘 작동하지만 FF 오류가 발생합니다 :자바 스크립트 '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에서 오류가 발생하지 않음).

관련 문제