@base-ui-components/react
Version:
Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
9 lines • 312 B
JavaScript
export function getOffset(element, prop, axis) {
if (!element) {
return 0;
}
const styles = getComputedStyle(element);
const start = axis === 'x' ? 'Left' : 'Top';
const end = axis === 'x' ? 'Right' : 'Bottom';
return parseFloat(styles[`${prop}${start}`]) + parseFloat(styles[`${prop}${end}`]);
}