Skip to content

reach/observe-rect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Chance Strickland
Jun 22, 2020
4da6901 · Jun 22, 2020

History

27 Commits
Jun 22, 2020
Jun 22, 2020
Jun 22, 2020
Jun 22, 2020
Jun 22, 2020
Jun 22, 2020
Jun 2, 2018
Jan 8, 2020
Jun 2, 2018
Jun 22, 2020
Jun 22, 2020
Jun 22, 2020

Repository files navigation

Reach observeRect

Observe the rect of a DOM element.

Demo

Installation

npm install @reach/observe-rect
# or
yarn add @reach/observe-rect

Usage

import observeRect from "@reach/observe-rect";

let node = document.getElementById("some-node");

let rectObserver = observeRect(node, rect => {
  console.log("left", rect.left);
  console.log("top", rect.top);
  console.log("height", rect.height);
  console.log("width", rect.width);
});

// start observing
rectObserver.observe();

// stop observing
rectObserver.unobserve();

About

A lot of things can change the position or size of an element, like scrolling, content reflows and user input. This utility observes and notifies you when your element's rect changes.

Legal

MIT License Copyright (c) 2018-present, Ryan Florence