Description
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 readded lazyload
. Modern browsers started working as expected, but IE11 din not(It's stuck with the background src it had before cloning).
var source = $(this);
var content = source.children().not('.lazysizes-display-clone').clone();
content.find('img').removeClass('lazyloaded').addClass('lazyload');
stage.find('#team-info-wrapper').empty().append( content );
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 with object-fit
that the logic stops.
I'm thinking that both readding the lazyload
class and calling lazySizes.autoSizer.checkElems()
should, in turn, trigger a reassessment of the bg image implemented by the object-fit
.
I hope this all made sense!
Cheers and much kudos for this excellent stuff. It's become an essential part of my toolkit!
Activity
aFarkas commentedon May 1, 2019
Could you write a simplified testcase over at jsfiddle, jsbin or whatever to showcase your problem?
Hlsgs commentedon May 1, 2019
Ofcourse:
https://jsfiddle.net/Hlsgs/exb60ghj/46/
https://jsbin.com/zelejeb/edit?html,css,js,output
The problme is, though, that in both cases, ls.object-fit doesn't seem to run at all in IE.
Improve object-fit polyfill handling (fixes #648)
aFarkas commentedon May 1, 2019
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?
Hlsgs commentedon May 1, 2019
I just tested and it seems to work fine. Both calling
lazySizes.autoSizer.checkElems()
and readding thelazyload
class work.That beeing said, I can see what you're saying about rubustness, as I've noticed some inconsistencies in that, whether one filters out
lazysizes-display-clone
when cloning or not, the resulting markup for the new clone is diferent from the original, contains the original img srcset and thedata-object-fit-polyfilled
attribute."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:
(max-aspect-ratio: 16/9) and (max-width: 1339px) calc( calc(100vh - 93px) * (16 / 9) ), (max-aspect-ratio: 16/9) and (min-width: 1340px) calc( calc(100vh - 144px) * (16 / 9) ), 100vw
:) ) and so decided to go all in with your stuff. Previously, I had been using a (way) more barbaric approach for poor old IE. And Edge, as this also covers video, which I still use it for.Have a look, if you're interested(video plugin, maybe? :)) ):