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 抛出错误:

evt 未定义

4

1 回答 1

1

您需要将mousemove事件传递到this.gUpdateMousePos()

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

IE 仅通过提供当前事件window.event。Firefox 仅通过传递给事件处理函数的参数提供它(您没有传递它,因此出现错误)。Chrome 和 Safari 两者都做(因此 Chrome 中没有错误)。

于 2010-12-06T16:56:58.350 回答