1.1.3 • Published 7 years ago

center-it v1.1.3

Weekly downloads
179
License
MIT
Repository
github
Last release
7 years ago

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

demo

include

by script

<script src="center-it.js"></script>

by npm

npm install center-it --save
var CenterIt = require('center-it')

usage

var centerIt = new CenterIt({
  containerWidth: 100,
  containerHeight: 100,
  originWidth: 600,
  originHeight: 400,
  centerType: 'cover' // "cover" or "contain"
})

centerIt.width() // return resized width in px
centerIt.height() // return resized height in px
centerIt.ratio() // return resized ratio of origin
centerIt.offset() // return offset {top, left} of origin in px

it provides two helper functions

// this is a helper function to set top left width height
centerIt.setPosition(el)

// this is a helper function to draw image into a canvas
centerIt.drawImage(context, image)
1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago