MouseUp在IE中不起作用(叹息!!!!) [英] MouseUp not working in IE (sigh!!!!)

查看:215
本文介绍了MouseUp在IE中不起作用(叹息!!!!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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事件没有触发,我必须再次单击以实际停止拉伸元素:(.请帮帮我.在鼠标移开时,它应该停止拉伸.

Everything works great in Chrome and Firefox, but in IE the stopstretch event is not firing and I have to click again to actually stop stretching the element :(. Please help me out. On mouseout it should stop stretching.

推荐答案

删除事件时,您需要传递用于添加事件的 identical 函数.

When you remove an event, you need to pass the identical function that you used to add it.

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

When you add an event handler you used: function() { stopstretching(watcherObj); } for mouseup and function() { stopstretching(watcherObj); } for mouseout (these two are different)

因此,删除时,您不能仅使用stopstretching,因为它不是您添加的.也许你可以拥有类似的东西

So when you remove, you can't just use stopstretching because it's not the one you added. Maybe you can have something like

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);

该代码未经测试,但我认为它应该可以工作.

The code is untested, but I think that it should work.

这篇关于MouseUp在IE中不起作用(叹息!!!!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆