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

getBoundingClientRect() async and without browser re-layout using intersection observer

Notifications You must be signed in to change notification settings

glued/async-bounds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;
  }
});

Releases

No releases published

Packages

No packages published