description
CenterIt
calculates width, height, ratio and offset when you want to center one rectangle into another, with designated center type (cover or contain)
demo
include
by script
by npm
npm install center-it --save
var CenterIt =
usage
var centerIt = containerWidth: 100 containerHeight: 100 originWidth: 600 originHeight: 400 centerType: 'cover' // "cover" or "contain" centerItwidth // return resized width in pxcenterItheight // return resized height in pxcenterIt // return resized ratio of origincenterIt // return offset {top, left} of origin in px
it provides two helper functions
// this is a helper function to set top left width heightcenterIt // this is a helper function to draw image into a canvascenterIt