1.4.5 • Published 2 years ago

element-measurer v1.4.5

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

ElementMeasurer

Build Status npm version Downloads

A javascript class that provides convenience for measuring size to target such as element or document.

Install

npm install element-measurer

Usage

import ElementMeasurer from 'element-measurer';

// Measures on an element.
// target: HTMLElement | 'selector' | document | window
const targetSize = new ElementMeasurer('#target');
let max = targetSize.maxScrollTop; // get maxScrollTop.

// Measures on the whole Document.
const docSize = new ElementMeasurer();
docSize.scrollTop = 200; // set scrollTop.

API

Image: element-and-client

Properties

  • clientWidth: ReadOnly Returns inner width of an element in pixels.
  • clientHeight: ReadOnly Returns inner height of an element in pixels.
  • scrollTop: Gets or sets of pixels that an element's content is scrolled vertically.
  • scrollLeft: Gets or sets the number of pixels that an element's content is scrolled to the left.
  • scrollWidth: ReadOnly Returns the width of the entire content of an element.
  • scrollHeight: ReadOnly Returns the height of the entire content of an element.
  • maxScrollTop: ReadOnly Returns maximum top scroll offset possible for the element.
  • maxScrollLeft: ReadOnly Returns maximum left scroll offset possible for the element.

Methods

setTarget

Set target element.

Syntax

elementMeasurer.setTarget(target);
  • @param Element|String|Window|Document target
  • @returns ElementMeasurer

getOffset

Returns top and left values that indicates offset distance to html document.

Syntax

let obj = elementMeasurer.getOffset();
  • @returns Object { top, left }

getRect

Returns DOMRect object of the target element.

Syntax

let domRect = elementMeasurer.getRect();

License

MIT License

1.4.5

2 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

5 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago