New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@threespot/object-fit-image

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@threespot/object-fit-image

object-fit polyfill for images

  • 1.0.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

object-fit Image Polyfill

npm Build Status Coverage Status

Polyfills object-fit: cover on <img> or <picture> tags by applying the src as an inline “background-image” on a target wrapper. Required for IE 11- and Android 4.4-. We recommend using Picturefill to polyfill the <picture> element itself.

Install

yarn add @threespot/object-fit-image

Usage

Markup

  <div class="bg-image">
    <img class="bg-image-source" src="https://satyr.io/320x16:9" srcset="https://satyr.io/320x16:9 320w, https://satyr.io/640x16:9 640w" alt="Image description.">
  </div>
import ObjectFitImage from "@threespot/object-fit-image";

var imageWrappers = document.querySelectorAll(".bg-image");

imageWrappers.forEach(el => new ObjectFitImage(el));

// With custom options
imageWrappers.forEach(el => new ObjectFitImage(el, {
  visuallyHiddenClass: "vh",
  backgroundPosition: "50% 0"
}));

Example styles for browsers that support object-fit:

  .bg-image {
    display: block;// for <picture> elements
    position: relative;

    &-source {
      height: 100%;
      left: 0;
      object-fit: cover;
      position: absolute;
      top: 0;
      width: 100%;
    }
  }

Additional markup examples

  <!-- Picture tag -->
  <picture class="bg-image">
    <source srcset="https://satyr.io/768x16:9/3" media="(min-width: 768px)">
    <source srcset="https://satyr.io/480x16:9/2" media="(min-width: 480px)">
    <img class="bg-image-source" src="https://satyr.io/320x16:9/1" alt="Image description 2 test.">
  </picture>

  <!-- Picture tag with wrapper -->
  <div class="bg-image">
    <picture class="bg-image-source">
      <source srcset="https://satyr.io/768x16:9/3" media="(min-width: 768px)">
      <source srcset="https://satyr.io/480x16:9/2" media="(min-width: 480px)">
      <img src="https://satyr.io/320x16:9/1" alt="Image description 1 test.">
    </picture>
  </div>

License

This is free software and may be redistributed under the terms of the MIT license.

About Threespot

Threespot is an independent digital agency hell-bent on helping those, and only those, who are committed to helping others. Find out more at https://www.threespot.com.

Threespot

Keywords

FAQs

Package last updated on 12 Nov 2018

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