getOuterSizes.js 652 B

123456789101112131415161718
  1. /**
  2. * Get the outer sizes of the given element (offset size + margins)
  3. * @method
  4. * @memberof Popper.Utils
  5. * @argument {Element} element
  6. * @returns {Object} object containing width and height properties
  7. */
  8. export default function getOuterSizes(element) {
  9. const window = element.ownerDocument.defaultView;
  10. const styles = window.getComputedStyle(element);
  11. const x = parseFloat(styles.marginTop || 0) + parseFloat(styles.marginBottom || 0);
  12. const y = parseFloat(styles.marginLeft || 0) + parseFloat(styles.marginRight || 0);
  13. const result = {
  14. width: element.offsetWidth + y,
  15. height: element.offsetHeight + x,
  16. };
  17. return result;
  18. }