Comments (7)
@bfred-it I did use the font-family as instructed in the readme. For instance:
.img-element {
height: 100%;
font-family: 'object-fit: contain;';
object-fit: cover;
width: 100%;
@include breakpoint(lg) {
font-family: none;
object-fit: none;
height: auto;
}
}
On window load, I was running objectFitImages(null, {watchMQ: true});
. The override in the CSS above wasn't working with this setup -- upon hitting the large breakpoint, the background image generated by OFI still existed and did not get removed.
Does the objectFitImages function have to get re-run on the document resize event as well?
from object-fit-images.
OFI works when you define the font-family
as instructed in the readme. Use that property in the media query as well and enable watchMQ
to make sure any changes made by Media Queries are picked up by OFI.
from object-fit-images.
It's not font-family: none
but font-family: "object-fit: none"
watchMQ is what enables OFI to run automatically on resize.
Also are you sure you're not looking for object-fit: fill
? That's the initial value; none
is a different behavior
from object-fit-images.
Thanks @bfred-it, that helped. Might be useful to update the readme to be a bit more explicit about how overrides work.
Is there a way to completely get rid of the background image polyfill at a specific breakpoint? Basically I want to go from object-fit: cover
on mobile to a normal inline image with max-width: 100%
on desktop.
from object-fit-images.
OFI just follows the CSS you feed it.
So if in a normal browser this is your code:
@media (max-width: 100px) {
img {
object-fit: cover;
width: 100px;
height: 100px;
}
}
This would be your equivalent ofi
code
@media (max-width: 100px) {
img {
object-fit: cover;
font-family: 'object-fit: cover';
width: 100px;
height: 100px;
}
}
If instead you need to re-set it:
img {
object-fit: cover;
font-family: 'object-fit: cover';
}
@media (max-width: 100px) {
img {
object-fit: fill;
font-family: 'object-fit: fill';
width: 100px;
height: 100px;
}
}
This is already covered by the docs: When you set object-fit
you also need to set font-family
to include the value of object-fit
as a string.
You can see it working in the new demo: https://bfred-it.github.io/object-fit-images/demo/
Since you're using SCSS, perhaps its mixin can make it easier: https://github.com/bfred-it/object-fit-images/blob/master/preprocessors/mixin.scss
from object-fit-images.
Thanks for the response @bfred-it.
Unfortunately, what I want to do is override the original object-fit property at a specific breakpoint entirely, so that the image reverts to a standard block-level element displayed at 100% width. For example:
img {
object-fit: cover;
font-family: 'object-fit: cover';
}
@media (max-width: 1024px) {
img {
object-fit: none;
font-family: 'object-fit: none';
height: auto;
width: 100%;
}
}
It doesn't seem this is possible now, as the polyfill generates a background-image fallback that doesn't get overriden if the object-fit property is later set to none.
Is that a feature you would consider adding? It would be hugely helpful for complex layouts that require object-fit at only some breakpoints.
from object-fit-images.
That works in the next version (3.0.0-0): npm install object-fit-images@next
or the one in this repo
from object-fit-images.
Related Issues (20)
- Assignment to read-only properties is not allowed in strict mode HOT 2
- Load event handler should get called when backgroundImage style is rendered. HOT 1
- Changing the src results in a "data-ofi-undefined" attribute. HOT 1
- Media Query images using `<source>` tag not working HOT 2
- Assignment to read-only properties is not allowed in strict mode HOT 13
- Fix documentation on es6 import HOT 7
- How to use this in angular project? HOT 2
- Error during tests HOT 2
- Test in IE with version 3.2.4 HOT 1
- IE11: Including the polyfill in two different libraries via ES6 imports then including both onto the page breaks it HOT 2
- > Assignment to read-only properties is not allowed in strict mode
- Doesn't support Edge 15 HOT 1
- react how to use ,ie11 is not working? HOT 1
- cloudinary videos is not working in IE 11 i.e object fit HOT 1
- Unable to use with Next HOT 2
- A request to have a de-initialization (cleanup) API HOT 2
- IE renders the svg object in background-image property HOT 10
- Uncaught (in promise) TypeError: _objectFitImages2.default.objectFitImages is not a function HOT 1
- Uses src when image has srcset HOT 4
- <picture> element in Edge HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from object-fit-images.