offsetter
This module is a simple thing does two things:
- moves (in the abstract) the center of your browser/css coordinate system to wherever you want, instead of the top-left corner.
- returns coordinates that offset your position to the middle of object (based on width & height)
npm install offsetter
usage
offsetter returns a function that you call with new center, relative to [0,0] in the top-left, so:
var offsetter = var center = windowinnerWidth / 2 windowinnerHeight / 2var offset =
The function that is returned from the constructor takes 3 args
var width = 20var height = 20var coord = -200 200var newCoordinate =
example
from ex.js
var offset = 500500 // sets the new [0,0] to [500,500] the page // ie. offset([window.innerWidth / 2, window.innerHeight]) // test centering at the new [0,0] a supposed object that is height and width zeroconsole // test position at [5,5], an item that is height and width 10console