niklasramo/mezr

Allow defining the element which the offset is calculated relative to in .offset() method

Closed this issue · 0 comments

Currently the .offset() method mimics the behaviour of jQuery's .offset() method, meaning that the measured element's offset is always relative to the document. However it would be pretty nice if one could define which element (or window, or document) the offset is relative to. This would also compensate the fact that Mezr currently does not have a comparable API method to jQuery's .position() method. This could be done without breaking backwards compatibility.

If the second argument is not a string we assume it is an element (or window, or document) definition. As per Mezr's generic API convention the element can be described with an array ([elem, edgeLayer]) or as an element.

The default syntax:

mezr.offset(elem, edgeLayer);

The new additional syntax:

mezr.offset([elem, edgeLayer], [elem, edgeLayer]);
mezr.offset([elem, edgeLayer]);

With the new syntax we could also mimic jQuery's position method pretty easily.

mezr.offset(elem, mezr.containingBlock(elem));