Bob Ippolito a écrit :

>
> I'll go ahead and add something to svn for 1.2, although it seems
> like it might be a little quirky depending on what the style.position
> is set to and it could be fairly hard to create proper automated
> tests for..
>
> http://mochikit.com/doc/html/MochiKit/DOM.html#fn-elementposition
>
> -bob

Great to see these functionalities in MochiKit. To be complete, it
would be great to have the possibility to have coordinates relative to
screen (code not fully tested):

MochiKi.DOM.screenPosition = function () {
   return {"x": MochiKi.DOM.docScrollLeft(), "y":
MochiKi.DOM.docScrollTop()}
}


MochiKi.DOM.docScrollLeft: function () {
    if (window.pageXOffset) {
        return window.pageXOffset;
    } else if (document.documentElement &&
           document.documentElement.scrollLeft) {
        return document.documentElement.scrollLeft;
    } else if (document.body) {
        return document.body.scrollLeft;
    } else {
        return 0;
    }
};


MochiKi.DOM.docScrollTop: function () {
    if (window.pageYOffset) {
        return window.pageYOffset;
    } else if (document.documentElement &&
               document.documentElement.scrollTop) {
        return document.documentElement.scrollTop;
    } else if (document.body) {
        return document.body.scrollTop;
    } else {
        return 0;
    }
};

(code adapted from OpenRico).

This way you can get screen-relative position using :
MochiKit.DOM.elementPosition(elem, MochiKit.DOM.screenPosition())

-- 
Thomas

Reply via email to