DNN 6 中的菜单位置混乱

发布于 2024-12-04 04:47:08 字数 835 浏览 1 评论 0原文

我的 DNN 模块有一些图像按钮,单击时会显示子菜单。正如预期的那样,菜单的绝对位置是使用 javascript 计算的。到目前为止,这一直运行良好(在 DNN4 和 DNN5 中)。但我们注意到 DNN6 中存在一个问题。菜单位置偏离了大量像素(可能有几百个)。 由于我没有编写计算代码,而且我也不是 JS 专家,所以我无法理解 DNN6 对它有何影响。 这是函数:

function AbsolutePosition(obj) {
        var pos = null;
        if(obj != null) {
            pos = new Object();
            pos.top = obj.offsetTop;
            pos.left = obj.offsetLeft;
            pos.width = obj.offsetWidth;
            pos.height= obj.offsetHeight;
            obj = obj.offsetParent;
            while(obj != null) {
                pos.top += obj.offsetTop;
                pos.left += obj.offsetLeft;
                obj = obj.offsetParent;
            }
        }
return(pos);
}

我想了解父页面结构如何影响这段代码 - 因为更改皮肤没有任何区别。这与页面元素的组织方式有关。

编辑:我也在寻找有关我可以尝试的代码修改的建议。

任何意见表示赞赏!谢谢。

My DNN module has some imagebuttons that show a sub-menu when clicked. The absolute position of the menu is calculated using javascript, as expected. This has worked well till now (In DNN4 and DNN5). But we are noticing a problem in DNN6. The menu position is off by a significant number of pixels (probably a couple hundred).
Since I did not write the calculation code, and neither am I a JS expert, I cannot understand how DNN6 is affecting it.
Here is the function:

function AbsolutePosition(obj) {
        var pos = null;
        if(obj != null) {
            pos = new Object();
            pos.top = obj.offsetTop;
            pos.left = obj.offsetLeft;
            pos.width = obj.offsetWidth;
            pos.height= obj.offsetHeight;
            obj = obj.offsetParent;
            while(obj != null) {
                pos.top += obj.offsetTop;
                pos.left += obj.offsetLeft;
                obj = obj.offsetParent;
            }
        }
return(pos);
}

I would like to understand how this code can be affected by the parent page structure - because changing the skin did not make any difference. This has something to do with how page elements are organized.

Edit: And I am also looking for suggestions regarding any modifications to the code that I could try.

Any input appreciated! Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪 2024-12-11 04:47:08

这与绝对定位的工作原理有关。当元素绝对定位时,其位置(由上面代码中的 topleft 元素表示)相对于其最近的祖先,具有 position relativeabsolute 的 code> 样式。在 DNN 6 中,模块包装器现在指定了 position:relative(新操作菜单使用它来定位)。新的控制面板也可能有一些类似的更改(如果菜单不在模块中)。

您可以尝试这个脚本,如果元素的位置是绝对相对,它就会停止爬树:

function AbsolutePosition(obj) {
    if (!obj) {
        return null;
    }

    var pos = {
        top: obj.offsetTop,
        left: obj.offsetLeft,
        width: obj.offsetWidth,
        height: obj.offsetHeight
    },
    positionsToStopAt = {
        relative: true,
        absolute: true
    };

    obj = obj.offsetParent;
    while(obj && !positionsToStopAt[jQuery(obj).css('position')]) {
        pos.top += obj.offsetTop;
        pos.left += obj.offsetLeft;
        obj = obj.offsetParent;
    }

    return pos;
}

This has to do with how absolute positioning works. When an element is absolutely positioned, its position (indicated by the top and left elements in the code above) is relative to its closest ancestor with a position style of either relative or absolute. In DNN 6, module wrappers now have position: relative specified on them (which the new action menu uses for positioning). There might also be some similar changes for the new control panel (if the menu isn't in a module).

You might try this script, which stops climbing the tree if the element's position is absolute or relative:

function AbsolutePosition(obj) {
    if (!obj) {
        return null;
    }

    var pos = {
        top: obj.offsetTop,
        left: obj.offsetLeft,
        width: obj.offsetWidth,
        height: obj.offsetHeight
    },
    positionsToStopAt = {
        relative: true,
        absolute: true
    };

    obj = obj.offsetParent;
    while(obj && !positionsToStopAt[jQuery(obj).css('position')]) {
        pos.top += obj.offsetTop;
        pos.left += obj.offsetLeft;
        obj = obj.offsetParent;
    }

    return pos;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文