element-coordinates
Element Coordinates is a minimal package for determining any element's basic positioning and sizing on the page. The top
, bottom
, left
, right
, height
and width
are provided for the element's content box (inner dimensions), padding box (content and padding, not including border) and border box (outer dimensions).
Installation
yarn add element-coordinates
ES6
;
CommonJS
var ElementCoordinates = ;
Global Script Include
Usage
To begin using Element Coordinates package, simply pass an element or css selector into the constructor and save the result:
var coordinates = ;
The resulting object will have three properties:
coordinates.borderBox
coordinates.paddingBox
coordinates.contentBox
Each of the box properties exposes the same properties as Element.getBoundingClientRect() but the values are relative to the document, instead of the scrolled viewport. Namely: top
, bottom
, left
, right
, height
and width
.
Example
See /examples/index.html for a full example, but the below is provided to show the syntax all together:
var coordinates = ;var borderBox = coordinatesborderBox;var contentBox = coordinatescontentBox;var space = contentBoxleft - borderBoxleft + 'px';console;