Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

center-it

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

center-it

`CenterIt` calculates width, height, ratio and offset when you want to center one rectangle into another, with designated center type (cover or contain)

  • 1.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-84.37%
Maintainers
1
Weekly downloads
 
Created
Source

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)

Keywords

FAQs

Package last updated on 11 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc