1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- const containsNode = require('./containsNode');
- function getElementRect(elem) {
- const docElem = elem.ownerDocument.documentElement;
-
-
- if (!('getBoundingClientRect' in elem) || !containsNode(docElem, elem)) {
- return {
- left: 0,
- right: 0,
- top: 0,
- bottom: 0
- };
- }
-
-
-
-
- const rect = elem.getBoundingClientRect();
- return {
- left: Math.round(rect.left) - docElem.clientLeft,
- right: Math.round(rect.right) - docElem.clientLeft,
- top: Math.round(rect.top) - docElem.clientTop,
- bottom: Math.round(rect.bottom) - docElem.clientTop
- };
- }
- module.exports = getElementRect;
|