-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lazySizes.autoSizer.checkElems() should trigger reassessment of bg image implemented by object-fit #648
Comments
Could you write a simplified testcase over at jsfiddle, jsbin or whatever to showcase your problem? |
Ofcourse: The problme is, though, that in both cases, ls.object-fit doesn't seem to run at all in IE. |
I just made some changes that should fix your issue. But I'm not really happy with the changes and not 100% sure about the robustness (Need to think about this). I must admit that this part is better handled by the object-fit-images polyfill of @bfred-it. At the same time I had once a bug report about some kind of race condition where the full polyfill had some issues showing the right image and I don't really understand why the project is archived and @bfred-it isn't supporting it anymore? |
I just tested and it seems to work fine. Both calling That beeing said, I can see what you're saying about rubustness, as I've noticed some inconsistencies in that, whether one filters out "Original" clone:
New clone:
To be honest, I'm not at all interested in adding another library. I've been using LS for some time, but only recently understood and totally got into the sizes=auto functionality(I used to write sizes attributes like this: Have a look, if you're interested(video plugin, maybe? :)) ): var supportsCSS = !!((window.CSS && window.CSS.supports) || window.supportsCSS || false);
var no_of_support = !supportsCSS || !CSS.supports( "(object-fit: cover)" ) || CSS.supports( "(-ms-ime-align: auto)" ); // (-ms-ime-align: auto) Edge because video
function o_fit( elements ) {
elements.each(function(index, el) {
var el_w_orig = $(this).attr("width") || 16;
var el_h_orig = $(this).attr("height") || 9;
if ( $(this).prop("tagName").toLowerCase() == "img" && supportsCSS && CSS.supports( "(object-fit: cover)" ) && CSS.supports( "(-ms-ime-align: auto)" ) ) return true; //skip for images on Edge
var container_w = $(this).parent().innerWidth();
var container_h = $(this).parent().innerHeight();
var scale_w = container_w / el_w_orig;
var scale_h = container_h / el_h_orig;
if ( $(this).hasClass('contain') ) {
var scale = scale_w > scale_h ? scale_h : scale_w;
} else {
var scale = scale_w > scale_h ? scale_w : scale_h;
}
$(this).width(scale * el_w_orig);
$(this).height(scale * el_h_orig);
$(this).addClass('no-object-fit');
});
}
if ( no_of_support ) o_fit( $('.cover, .contain') ); .of-container {
position: relative;
overflow: hidden;
}
.cover,
.contain {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
&.no-object-fit {
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-width: none;
}
}
.contain {
object-fit: contain;
} |
I am using LS with parent-fit, object-fit and respimg. Some interesting "issues" arose when cloning an element that contains an image already handled by the plugins:
If cloning and appending said element somewhere where it has different dimensions via CSS, the auto-sizes functionality does not do it's job out of the box. Since LS auto-detects elements added to the DOM, I wondered what exactly in the cloned nodes was stopping that, so I removed the
lazyloaded
class and readdedlazyload
. Modern browsers started working as expected, but IE11 din not(It's stuck with the background src it had before cloning).My next idea was adding
lazySizes.autoSizer.checkElems()
after appending the element, and, again, modern browsers cool, IE bad.I then did a quick check without
object-fit
, and everything was fine in IE, so I guess it's withobject-fit
that the logic stops.I'm thinking that both readding the
lazyload
class and callinglazySizes.autoSizer.checkElems()
should, in turn, trigger a reassessment of the bg image implemented by theobject-fit
.I hope this all made sense!
Cheers and much kudos for this excellent stuff. It's become an essential part of my toolkit!
The text was updated successfully, but these errors were encountered: