All Projects โ†’ fregante โ†’ Object Fit Images

fregante / Object Fit Images

Licence: mit
๐Ÿ—ป Polyfill object-fit/object-position on <img>: IE9, IE10, IE11, Edge, Safari, ...

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to Object Fit Images

Monocle
PowerShell Web Automation module, made to make automating websites easier
Stars: โœญ 47 (-97.71%)
Mutual labels:  edge, ie
parcel-plugin-goodie-bag
provides the Promise and fetch goodies needed for IE(11) support w/ parcel bundle loading
Stars: โœญ 15 (-99.27%)
Mutual labels:  polyfill, ie
history-of-ie-incompatible-sites-list
History of IE incompatible sites list provided by Microsoft to redirect from IE11 to Chromium Edge
Stars: โœญ 29 (-98.59%)
Mutual labels:  edge, ie
Ipyplot
IPyPlot is a small python package offering fast and efficient plotting of images inside Python Notebooks. It's using IPython with HTML for faster, richer and more interactive way of displaying big numbers of images.
Stars: โœญ 152 (-92.59%)
Mutual labels:  images
Samsa
Variable font inspector
Stars: โœญ 153 (-92.54%)
Mutual labels:  polyfill
Node Imgur
Upload images to imgur.com
Stars: โœญ 161 (-92.15%)
Mutual labels:  images
Iphone Inline Video
๐Ÿ“ฑ Make videos playable inline on the iPhone (prevents automatic fullscreen)
Stars: โœญ 2,020 (-1.46%)
Mutual labels:  polyfill
Vitedge
Edge-side rendering and fullstack Vite framework
Stars: โœญ 150 (-92.68%)
Mutual labels:  edge
Server
The Triton Inference Server provides an optimized cloud and edge inferencing solution.
Stars: โœญ 2,994 (+46.05%)
Mutual labels:  edge
Paperclip Meta
Adds width, height, and size to paperclip images.
Stars: โœญ 157 (-92.34%)
Mutual labels:  images
Salt
Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
Stars: โœญ 12,086 (+489.56%)
Mutual labels:  edge
Rawloader
rust library to extract the raw data and some metadata from digital camera images
Stars: โœญ 153 (-92.54%)
Mutual labels:  images
Vue Displacement Slideshow
A Vue.js 2.0 slideshow component working with Three.js
Stars: โœญ 165 (-91.95%)
Mutual labels:  images
React Intense
A React component for viewing large images up close ๐Ÿ”
Stars: โœญ 152 (-92.59%)
Mutual labels:  images
Assetchecker
๐Ÿ‘ฎSanitize your Assets.xcassets files
Stars: โœญ 167 (-91.85%)
Mutual labels:  images
Navigator.sendbeacon
Polyfill for Navigator.sendBeacon()
Stars: โœญ 151 (-92.63%)
Mutual labels:  polyfill
China Domain Allowlist
ๅธธ็”จไธญๅ›ฝ็ฝ‘็ซ™็™ฝๅๅ•๏ผŒ็บฏๅˆ—่กจ๏ผŒ็”จไบŽ SwitchyOmega๏ผŒๆŽงๅˆถไธ่ตฐไปฃ็†็š„็ฝ‘็ซ™ใ€‚
Stars: โœญ 166 (-91.9%)
Mutual labels:  edge
Polyfill Php73
This component provides functions unavailable in releases prior to PHP 7.3.
Stars: โœญ 2,121 (+3.46%)
Mutual labels:  polyfill
Spectrum
A client-side image transcoding library.
Stars: โœญ 1,908 (-6.93%)
Mutual labels:  images
Awesomeimagepicker
Awesome Image Picker library will pick images/gifs with beautiful interface. Supports image or gif, Single and Multiple Image selection.
Stars: โœญ 160 (-92.2%)
Mutual labels:  images

object-fit-images gzipped size build status npm CDNJS jsDelivr

๐Ÿ—ป Polyfill object-fit/object-position on <img>: IE9, IE10, IE11, Edge, Safari, ...

  • Fast and lightweight (demo)
  • No additional elements are created
  • Setup is done via CSS
  • Scaling is taken care by the browser (it uses background-size)
  • srcset support
  • src and srcset properties and attributes keep working: img.src = 'other-image.jpg'

Alternative solutions

Comparison fregante
/object-fit-images๐ŸŒŸ
constancecchen
/object-fit-polyfill
tonipinel
/object-fit-polyfill
Browsers IEdge 9-14, Android<5, Safari<10 <- Same "All browsers"
Tags img image video picture img
cover/contain ๐Ÿ’š ๐Ÿ’š ๐Ÿ’š
fill ๐Ÿ’š ๐Ÿ’š ๐Ÿ’š
none ๐Ÿ’š ๐Ÿ’š ๐Ÿ’š
scale-down ๐Ÿ’š using {watchMQ:true} ๐Ÿ’š ๐Ÿ’”
object-position ๐Ÿ’š ๐Ÿ’š ๐Ÿ’”
srcset support ๐Ÿ’š Native or picturefill notes ๐Ÿ’š ๐Ÿ’”
Extra elements ๐Ÿ’š No ๐Ÿ’” Yes ๐Ÿ’” Yes
Settings ๐Ÿ’š via CSS ๐Ÿ’” via HTML ๐Ÿ’” via HTML

Usage

You will need 3 things

  1. one or more <img> elements with src or srcset

    <img class='your-favorite-image' src='image.jpg'>
  2. CSS defining object-fit and a special font-family property to allow IE to read the correct value

    .your-favorite-image {
    	object-fit: contain;
    	font-family: 'object-fit: contain;';
    }

    or, if you also need object-position

    .your-favorite-image {
    	object-fit: cover;
    	object-position: bottom;
    	font-family: 'object-fit: cover; object-position: bottom;';
    }

    To generate the font-family automatically, you can use the PostCSS plugin or the SCSS/SASS/Less mixins.

    If you set the font-family via JavaScript (which must be followed by calling objectFitImages()), make sure to include the quotes in the property.

  3. the activation call before </body>, or on DOM ready

    objectFitImages();
    // if you use jQuery, the code is: $(function () { objectFitImages() });

    This will fix all the images on the page and also all the images added later (auto mode).

    Alternatively, only fix the images you want, once:

    // pass a selector
    objectFitImages('img.some-image');
    // an array/NodeList
    var someImages = document.querySelectorAll('img.some-image');
    objectFitImages(someImages);
    // a single element
    var oneImage = document.querySelector('img.some-image');
    objectFitImages(oneImage);
    // or with jQuery
    var $someImages = $('img.some-image');
    objectFitImages($someImages);

    You can call objectFitImages() on the same elements more than once without issues, for example to manually request an update of the object-fit value.

Apply on resize

You don't need to re-apply it on resize, unless:

In one of those cases, use the watchMQ option:

objectFitImages('img.some-image', {watchMQ: true});
// or objectFitImages(null, {watchMQ: true}); // for the auto mode

Install

Pick your favorite:

<script src="dist/ofi.min.js"></script>
<!-- CDN is also available, but I suggest you concatenate JS files instead -->
<!-- Visit https://cdnjs.com/libraries/object-fit-images -->
npm install --save object-fit-images
var objectFitImages = require('object-fit-images');
import objectFitImages from 'object-fit-images';

API

objectFitImages(images, options)

Both parameters are optional.

parameter description
images Type: string, element, array, NodeList, null
Default: null

The images to fix. More info in the Usage section
options Type: object
Default: {}
Example: {watchMQ:true}

watchMQ Type: boolean
Default: false

This enables the automatic re-fix of the selected images when the window resizes. You only need it in some cases

License

MIT ยฉ Federico Brigante

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].