Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
object-fit-images
Advanced tools
Adds support to object-fit to images on IE9, IE10, IE11, Edge and other old browsers.
Adds support to
object-fit
to images on IE9, IE10, IE11, Edge and other old browsers.
This script was made with the main use-case in mind: images. Take a look at the demo.
<img>
's src
attribute: img.src = 'other-image.jpg'
object-fit-images | tonipinel/object-fit-polyfill | jonathantneal/fitie | |
---|---|---|---|
Browsers | "All browsers" | "All browsers" | IE 8-11, Edge |
Tags | img | img | img , video |
cover/contain | 💚 | 💚 | 💚 |
fill | 💚 | 💚 | 💚 |
none | 💚 | 💚 | 💔 |
scale-down | 💛 Mapped to contain | 💔 | 💔 |
object-position | 💚 | 💔 | 💔 |
srcset support | 💚 Native or picturefill, but no Edge 12 | 💔 | 💔 |
object-fit-images | tonipinel/object-fit-polyfill | jonathantneal/fitie | |
---|---|---|---|
Size | 1.3KB | 1.8KB | 1.5KB |
Update wait | 💚 No wait, applied before image load | 💚 No wait, applied before image load | 💔 Wait until full image load |
Additional DOM elements necessary | 💚 No | 💔 Yes, a wrapping element is added | 💔 Yes, a wrapping element is added |
Performance overhead | 💰 | 💰💰💰 | 💰💰 |
Technique description | Transparent src image; Image in <img> 's background | Wrapper element with style copied from <img> ; CSS+JS positioning; Original <img> hidden | Wrapper element with style copied from <img> ; JS positioning |
object-fit-images | tonipinel/object-fit-polyfill | jonathantneal/fitie | |
---|---|---|---|
Object-fit definition | 💛 In CSS, via font-family property * | 💔 Via data attribute in HTML (data-object-fit="cover" ) | 💔 Via class in HTML (class="cover" ) |
Support changes in @media query | 💚 Optional, with {watchMQ:true} | 💔 No | 💔 No |
Updates on resize | 💚 Unnecessary | 💚 Unnecessary | 💔 Yes, manually |
Fix new elements automatically | 💚 Optional, with objectFitImages() or objectFitImages(false) | 💔 Impossible | 💛 Manually |
<img> src changes | 💚 Automatically reflected | 💔 Image not updated at all | 💔 Fix not updated |
Other limitations | 💔 Any onload events on <img> will fire again when it fixes | 💚 I didn't find any | 💔 Some CSS declaration might be broken because partially moved to the wrapper |
Runner-ups:
Because it's nearly impossible to read unsupported property, object-fit-images
reads the value of object-fit
and object-position
from the font-family
property on img
.
.your-favorite-image {
object-fit: contain;
font-family: 'object-fit: contain;'
}
.your-second-favorite {
object-fit: contain;
object-position: bottom;
font-family: 'object-fit: cover; object-position: bottom'
}
This has no effect on the rendering because it's ignored by the browser.
A PostCSS plugin could also be developed to automatically add this font-family
property.
There are already SCSS/SASS/Less mixins in the preprocessor
folder to create that font-family
automatically, like this:
@import "object-fit-images/preprocessors/mixin.scss";
img { @include object-fit(cover, top); }
Fix all the images on the page, present and future (auto mode)
objectFitImages();
// or objectFitImages(false)
Alternatively, just fix them once. The first parameter can be:
// 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);
If your media queries change the value of object-fit
, like this:
img { object-fit: cover }
@media (max-width: 500px) { img { object-fit: contain } }
... then you need to enable the media queries support like this:
objectFitImages('img.some-image', {watchMQ: true});
// or objectFitImages(false, {watchMQ: true}); // for the auto mode
<script src="ofi.min.js"></script>
<script>objectFitImages();</script>
npm install --save object-fit-images
var objectFitImages = require('object-fit-images');
objectFitImages();
objectFitImages([images, [opts]])
parameter | description |
---|---|
images | Type: string (as a selector) or array -like optional The images to apply the fix on. If it's not supplied (or false ), OFI will enter the automatic mode (which means that new images in the DOM will automatically be fixed). |
opts | Type: object optional Set to {watchMQ: true} if you expect object-fit to vary in a media query. |
onresize
default: the values rarely change with media queries, so only enable them when needed with {watchMQ:true}
srcset
supportMIT © Federico Brigante
FAQs
Polyfill object-fit and object-position on images on IE9, IE10, IE11, Edge, Safari, ...
The npm package object-fit-images receives a total of 22,560 weekly downloads. As such, object-fit-images popularity was classified as popular.
We found that object-fit-images demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.