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'
})
centerIt.width()
centerIt.height()
centerIt.ratio()
centerIt.offset()
it provides two helper functions
centerIt.setPosition(el)
centerIt.drawImage(context, image)