Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Latest commit

 

History

History
44 lines (32 loc) · 996 Bytes

README.md

File metadata and controls

44 lines (32 loc) · 996 Bytes

async-bounds

Uses IntersectionObserver to get the bounds of an element without causing browser re-layout as an alternative to element.getBoundingClientRect()

npm version

Install

npm install async-bounds --save

Usage

Single element

import asyncBounds from 'async-bounds';
asyncBounds(element).then(bounds => {
  const { x, y, width, height } = bounds;
  console.log(bounds);
});

Or async

import asyncBounds from 'async-bounds';
const { x, y, width, height } = await asyncBounds(element);

Or Multiple elements

import asyncBounds from 'async-bounds';

// Spread array in, array out
const elements = document.querySelectorAll('div');
asyncBounds(...elements).then(boundsArray => {
  for (const bounds of boundsArray) {
    const { x, y, width, height } = bounds;
  }
});