APE.dom.getOffsetCoords()

One of the most powerful features of APE.dom is getOffsetCoords(el, container[, coords]);.

What is it?

APE.dom.getOffsetCoords returns the coordinates of the element relative to an optional ancestor, e.g. { x : 10, y : 10 }

click me!

It works

I tested the shit out of it. Please find a case where getOffsetCoords() will fail.

Speed is King

Function APE.dom.getOffsetCoords() is blazingly fast. Results in a complex tree with scrolled parents takes on average 2.5ms in Firefox (the worst performer).

Cross-browser Woes

Finding an element's position is extremely hard. It is hard because of differences in offsetTop, offsetLeft, and offsetParent.

Compare to [insert_library_here]

Other libraries have attempted to address these differences with browser detection. This is bad for a few reasons:

  1. when [browser_x] fixes a bug that had a specific workaround based on a browser check, the code will fail (and rightly so).
  2. the event of (1) occurring is less likely if the script is used in widespread library code.

Other libraries will fail when there is margin and position on body.

They're also slower. Some of the "better" libraries take up to 15ms to return wrong results. That sucks!