FBJS 函数 getAbsoluteLeft 的 Javascript 替代方案

发布于 2024-12-23 14:59:55 字数 143 浏览 6 评论 0原文

我正在将一个项目从以前的 Facebook Api (FBJS) 迁移到新的 API。有一个函数的名称为:

getAbsoluteLeft()

我不知道为什么使用它。谁能提供它的 javascript 替代品吗?

I am migrating a project from previous Facebook Api (FBJS) to the new API. There is a function with the name:

getAbsoluteLeft()

I have no idea why this is used. Can anyone provide its javascript alternate?

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

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

发布评论

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

评论(2

彻夜缠绵 2024-12-30 14:59:55

根据文档页面 getAbsoluteLeft 上的描述

与 getAbsoluteTop 相同,但水平方向。

获取绝对顶部:

返回元素相对于左侧的绝对位置
页。由于缺乏 offsetParent 支持而很有用。

如果您在 iFrame 中使用 jQuery,则可以使用 offset 函数来获取元素的左侧和顶部。

var position = $(element).offset();

According to what is described on the documentation page

getAbsoluteLeft:

Same as getAbsoluteTop, but horizontally.

getAbsoluteTop:

Returns the elements absolute position relative to the left of the
page. Useful because of lack of offsetParent support.

If you are using jQuery in iFrame, you can use the offset function to get left and top of the element.

var position = $(element).offset();
妄司 2024-12-30 14:59:55

好吧,我也没有找到代码本身。
这是我在我的一个项目中使用的类似代码,

function getCoords(obj){
    if (getCoordsCache.obj == obj) {
    return getCoordsCache.pos;
    } else {
    var o = obj;
        var ret={'l':o.offsetLeft,'t':o.offsetTop,'w':o.offsetWidth,'h':o.offsetHeight}
        while(o=o.offsetParent){
            ret.l+=o.offsetLeft;
            ret.t+=o.offsetTop;
        }
        getCoordsCache.obj = obj;
        getCoordsCache.pos = ret;
        return ret;
    }
}

它返回具有 lefttop 属性的对象。因此,对于 getAbsoluteLeft 只需返回 getCoords(obj).left

如果你有的话,像另一个答案一样使用 jQuery 会更好。

Ok, I haven't found the code itself too.
Here's the similar code, I used in ony of my project

function getCoords(obj){
    if (getCoordsCache.obj == obj) {
    return getCoordsCache.pos;
    } else {
    var o = obj;
        var ret={'l':o.offsetLeft,'t':o.offsetTop,'w':o.offsetWidth,'h':o.offsetHeight}
        while(o=o.offsetParent){
            ret.l+=o.offsetLeft;
            ret.t+=o.offsetTop;
        }
        getCoordsCache.obj = obj;
        getCoordsCache.pos = ret;
        return ret;
    }
}

It returns object with left and top properties. So for getAbsoluteLeft just return getCoords(obj).left.

Using jQuery like in another answer is even better, if you have it.

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