try {
box = elem.getBoundingClientRect();
+ } catch(e) {}
- } catch(e) {
- return { top: 0, left: 0 };
+ var doc = elem.ownerDocument,
+ docElem = doc.documentElement;
+
+ // Make sure we're not dealing with a disconnected DOM node
+ if ( !box || !jQuery.contains( docElem, elem ) ) {
+ return box || { top: 0, left: 0 };
}
- var doc = elem.ownerDocument,
- body = doc.body,
- docElem = doc.documentElement,
+ var body = doc.body,
win = getWindow(doc),
clientTop = docElem.clientTop || body.clientTop || 0,
clientLeft = docElem.clientLeft || body.clientLeft || 0,