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

fitobject

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fitobject

Fit an object to cover or be contained by its container.

  • 0.2.1
  • Source
  • npm
  • Socket score

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

fitobject

Given an object and its container, size and position the object to fit the container based on the fit parameter according to the behavior of the 'cover' and 'contain' values of the CSS background-size property.

Install

npm install fitobject

Usage

<div class="container">
  <img class="object" src="http://placehold.it/400x300" />
</div>

<script>
  var fitObject = require('fitobject');
  fitObject('.object', '.container', 'cover');
</script>

The third argument specifies how the object should be fit to its container. Specify either 'cover' or 'contain'.

The fitObject function also accepts a "safe area" as a fourth, optional argument an object. When the object fit method is set to 'cover', the safe area can define a region of the object to avoid cropping into.

Here is the above example again with a safe area defined:

var safeArea = {
  'top': 25,   // 25% of the vertical dimension from the top
  'right': 0,  // 0% of the horizontal dimension from the right
  'bottom': 0, // 0% of the vertical dimension from the bottom
  'left': 50   // 50% of the horizontal dimension from the left
}

fitObject('.object', '.container', 'cover', safeArea);

FAQs

Package last updated on 11 May 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