overlap(mode, element) -> Number

Returns a Number between 0 and 1 corresponding to the proportion to which element overlaps the point previously defined by Position.within. mode can be set to either vertical or horizontal.


Imagine a block-level element (i.e., with dimensions) and a point x, y measured in pixels from the top left corner of the page. Calling Position.within will indicate whether that point is within the area occupied by element.

Now imagine an element of equal dimensions to element with its top left corner at x, y. Position.overlap indicates the amount these two boxes overlap in either the horizontal or vertical direction.

Note that Position.within must be called right before calling this method.


var element = $('some_positioned_element');
// -> [100, 100] (element is 100px from the top and left edges of the page)
// -> { width: 150, height: 150 }

Position.within(element, 175, 145);
// -> true

Position.overlap('horizontal', element);
// -> 0.5 (point is halfway across the element's length)

Position.overlap('vertical', element);
// -> 0.3 (point is 3/10ths of the way across the element's height)