region
A helper to work with rectangular regions in the DOM
Install
$ npm install region --save
Usage
var Region = var region = region == 60region == 70
API
Instantiation
You can create a new Region by calling the function returned by require('region')
. You can call it as a constructor if you want.
var Region = top: 10 left: 10 //either width,height //or right, bottom width: 10 height: 10
or
var Region = var r =
You can instantiate a Region
from a DOM node, using Region.fromDOM (NOTE: uses dom.offsetWidth/Height/Left/Top for getting coordinates)
var r = Region
Getters
- get - returns an object with {top, left, bottom, right}
- getWidth
- getHeight
- getLeft
- getTop
- getRight
- getBottom
- getPosition - returns an object with {left, top}
- getSize - returns an object with {width, height}
containsPoint(x,y) or containsPoint({x,y}) : Boolean
var r = r == truer == true
equals(r): Boolean
Returns true if this region equals the region (or the object) given as the first param var r = Region({top: 10, left: 10, bottom: 20, right: 20 })
r.equals({top: 10, left: 10, bottom: 20, right: 20 }) == true
equalsPosition({top, left}): Boolean
Returns true if this region has top, left equal to the given coordinates
equalsSize({width, height}): Boolean
Returns true if this region has the same size as the given region or object
var coords = top: 10 left: 10 width: 100 height: 100 var r = r == truer == true
getIntersection(Region): Region/false
Returns the region resulted by intersecting this region with the given region. If no intersection, returns false
clone: Region
Returns a new region instance with the same coordinates
var r = left: 10 right: 10 width: 10 height: 20r
Tests
$ make
Watch mode
$ make test-w
License
MIT