DNN 6 中的菜单位置混乱
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这与绝对定位的工作原理有关。当元素绝对定位时,其位置(由上面代码中的
top
和left
元素表示)相对于其最近的祖先,具有position
relative
或absolute
的 code> 样式。在 DNN 6 中,模块包装器现在指定了position:relative
(新操作菜单使用它来定位)。新的控制面板也可能有一些类似的更改(如果菜单不在模块中)。您可以尝试这个脚本,如果元素的位置是
绝对
或相对
,它就会停止爬树:This has to do with how absolute positioning works. When an element is absolutely positioned, its position (indicated by the
top
andleft
elements in the code above) is relative to its closest ancestor with aposition
style of eitherrelative
orabsolute
. In DNN 6, module wrappers now haveposition: 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
orrelative
: