Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
object-fit-images
Advanced tools
Polyfill object-fit and object-position on images on IE9, IE10, IE11, Edge, Safari, ...
Polyfill
object-fit
andobject-position
on images on IE9, IE10, IE11, Edge, Safari, ...
This adds support for object-fit
and object-position
to IEdge 9-13, Android 4.4-, Safari (OSX 9.1-, iOS 9.3-) and skips browsers that already support them.
Take a look at the demo.
<img>
's src
attribute: img.src = 'other-image.jpg'
srcset
supportobject-fit-images | tonipinel/object-fit-polyfill | jonathantneal/fitie | |
---|---|---|---|
Browsers | IEdge 9-14, Android < 5, Safari < 10 | "All browsers" | IE 8-11 |
Tags | img | img | img , video |
cover/contain | 💚 | 💚 | 💚 |
fill | 💚 | 💚 | 💚 |
none | 💚 | 💚 | 💔 |
scale-down | 💚 {watchMQ:true} suggested | 💔 | 💔 |
object-position | 💚 | 💔 | 💔 |
srcset support | 💚 Native or picturefill, but see notes | 💔 | 💔 |
picture support | 💛 Exclusively where picturefill acts* | 💔 | 💔 |
Performance and ease of use considerations in extended-comparison.md
You will need 3 things
one or more <img>
elements with src
or srcset
<img class='your-favorite-image' src='image.jpg'>
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.
the activation call before </body>
, on 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);
resize
You don't need to re-apply it on resize
, unless:
You're using scale-down
, or
your media queries change the value of object-fit
, like this
img { object-fit: cover }
@media (max-width: 500px) { img { object-fit: contain } }
In one of those cases, use the watchMQ
option:
objectFitImages('img.some-image', {watchMQ: true});
// or objectFitImages(null, {watchMQ: true}); // for the auto mode
npm install --save object-fit-images
var objectFitImages = require('object-fit-images');
If you don't use browserify/webpack, include this instead:
<script src="dist/ofi.browser.js"></script>
objectFitImages([images, [options]])
parameter | description |
---|---|
images |
Type: string , element , array , NodeList , null Default: null
|
objectFitImages()
on the same elements more than once without issues (for example if you decide to change anything on resize)MIT © 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
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.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.