npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fitobject

v0.4.7

Published

A jQuery plugin to fit an object to its container.

Downloads

20

Readme

fitObject

A jQuery plugin to fit an object to its container according to a fit parameter that behaves similarly to the CSS background-size keyword syntax.

Codepen Example

Install

npm install fitobject

Usage

For simple cover fitting of an object to a container:

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

<script>
  $('.object').fitObject();
</script>

You can size and position the object to be totally contained inside the container, as with the CSS property background-size: contain:

$('.object').fitObject('contain');

Cover fit safe area

Specify a safeArea parameter to define a region of the object to avoid cropping into when the object fit method is set to 'cover'.

$('.object').fitObject({
  '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
  }
});

Non-immediate ancestor fit container

By default, fitObject will fit your object to its immediate parent, but can fit to ancestors further up the DOM tree by setting the container parameter, assuming any parents between are set to position: static.

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

<script>
  $('.object').fitObject({
    'container': '.container'
  });
</script>

Object data attributes

Each of the fitObject parameters can be set via HTML data attributes on the object to fit:

<div class="container">
  <img class="object" src="http://placehold.it/400x300"
    data-object-fit="cover"
    data-fit-container=".container"
    data-safe-area="{'top':0,'right':21.23,'bottom':0,'left':19.33}"
  />
</div>

<script>
  $('.object').fitObject();
</script>

Object data attributes will supersede parameters passed into the fitObject method.

List of parameters

|Parameter | Data Attribute | Type | Default | Description | |---|---|---|---|---| | container | fit-container | String, DOM Node, jQuery DOM element | First parent not classed .fit-object-wrapper | The container to fit the object to | | fit | object-fit | String | 'cover' | The fit method – either 'cover' or 'contain' | | safeArea | safe-area | Object | { 'top': 0, 'right': 0, 'bottom': 0, 'left': 0 } | An area of the object to avoid cropping into. Specify a percentage of the X or Y dimension for each side. |