MouseUp无法在IE中工作(叹息!!!!)

时间:2011-01-04 15:57:03

标签: javascript mouseevent

function startstretchright(aObj) {
    watcherObj = aObj.parentNode.parentNode;

    var dragWorkspaceDiv = document.createElement("div");
    var dragWorkspaceObj = document.body.appendChild(dragWorkspaceDiv);
    dragWorkspaceObj.id = "dragWorkspace";
    dragWorkspaceObj.style.position = "absolute";
    dragWorkspaceObj.style.left = "0px";
    dragWorkspaceObj.style.top = "0px";
    dragWorkspaceObj.style.width = "100%";
    dragWorkspaceObj.style.height = "100%";
    dragWorkspaceObj.style.cursor = "hand";
    dragWorkspaceObj.style.cursor = "pointer";
    dragWorkspaceObj.style.background = "#000000";
    dragWorkspaceObj.style.filter = "alpha(opacity=1)";
    dragWorkspaceObj.style.opacity = .01;
    dragWorkspaceObj.style.MozOpacity = .01;
    dragWorkspaceObj.style.zIndex = "400";

    addEvent(dragWorkspaceObj, 'mouseup', function() { stopstretching(watcherObj); });
    addEvent(dragWorkspaceObj, 'mouseout', function() { stopstretching(watcherObj); });
    addEvent(dragWorkspaceObj, 'mousemove', continuestretching);

    stretchDirection = "right";
    initialX = locateObject(aObj).x;
    initialLeft = watcherObj.style.marginLeft;
    initialWidth = watcherObj.style.width;

    watcherObjLeftBoundary = 0;
    watcherObjRightBoundary = (document.getElementById("dayHeaderContainer").getElementsByTagName("DIV").length * 100);
    var siblingArr = watcherObj.parentNode.getElementsByTagName("DIV");
    var initialLeftEdge = parseFloat(aObj.parentNode.parentNode.style.marginLeft);
    var initialRightEdge = initialLeftEdge + parseFloat(aObj.parentNode.parentNode.style.width);
    for (var i = 0; i < siblingArr.length; i++) {
        if (siblingArr[i].className == "watcher" && siblingArr[i] != watcherObj) {
            var l = parseFloat(siblingArr[i].style.marginLeft);
            var r = l + parseFloat(siblingArr[i].style.width);
            if (r > watcherObjLeftBoundary && r <= initialLeftEdge) {
                watcherObjLeftBoundary = r;
            }
            if (l < watcherObjRightBoundary && l >= initialRightEdge) {
                watcherObjRightBoundary = l;
            }
        }
    }
}

停止拉伸功能

function stopstretching(watch) {
    watcherObj = null;
    removeEvent(document.getElementById("dragWorkspace"), 'mouseup', stopstretching);
    removeEvent(document.getElementById("dragWorkspace"), 'mouseout', stopstretching);
    removeEvent(document.getElementById("dragWorkspace"), 'mousemove', continuestretching);
    var objToRemove = document.getElementById("dragWorkspace");
    if (document.all) {
        var oldLayer = objToRemove.removeNode(true);
    } else {
        var oldLayer = objToRemove.parentNode.removeChild(objToRemove);
    }

}

在Chrome和Firefox中一切都很好用,但在IE中,stopstretch事件没有触发,我必须再次点击才能实际停止拉伸元素:(。请帮我解决。在鼠标输出时它应该停止拉伸。

1 个答案:

答案 0 :(得分:0)

删除活动时,您需要传递用于添加活动的相同功能。

当您添加使用的事件处理程序时:function() { stopstretching(watcherObj); } mouseupfunction() { stopstretching(watcherObj); } mouseout(这两个不同)

因此,当您删除时,您不能只使用stopstretching,因为它不是您添加的那个。也许你可以拥有像

这样的东西
function stopHandler() {
    stopstretching(watcherObj, stopHandler);
}
addEvent(dragWorkspaceObj, 'mouseup', stopHandler);
addEvent(dragWorkspaceObj, 'mouseout', stopHandler);

function stopstretching(watch, handler) {
    watcherObj = null;
    removeEvent(document.getElementById("dragWorkspace"), 'mouseup', handler);
    removeEvent(document.getElementById("dragWorkspace"), 'mouseout', handler);

代码未经测试,但我认为它应该有用。