-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Workaround/Idea: Preloading images with srcset attributes (chrome) #166
Comments
@rs3d Thanks, it works fine for me. Btw: is there any good reason to use 100ms in setTimeout? Because it works fine with 0ms for me. |
Unfortunately, I haven't tackled |
Hi @Ppavell, when I was using currentSrc, it wasn't computed on pageload. I used 100ms to save cpu performance. With 0ms waitForComputedSrcset is called very often. Insert a console.log and try some different timeouts to see the difference. |
Hi @hatsumatsu, here is a rough pen: http://codepen.io/rawbitz/pen/WbZMem (only tested in Mac/Chrome 40) |
Thanks @rs3d, I'll give it a try, looks very promising! |
The workaround from @rs3d is doing the trick now for me. It's loading fine in Chrome 40 (PC) |
Hi, I did not find a solution with imagesLoaded for my issue than I wrote a simple function with some jQuery improvemens. That works for me now without imagesLoaded library: My Pen: http://codepen.io/hayatbiralem/pen/jbjLZe?editors=001 var imagesLoaded = function(selector, onComplete, onProgress) {
var $images = $(selector).find('img');
var success = 0;
var error = 0;
var iteration = 0;
var total = $images.length;
var check = function(el, status) {
iteration++;
var data = {
img: el,
iteration: iteration,
success: success,
error: error,
total: total,
status: status
};
$.isFunction(onProgress) && onProgress(data);
if (success + error === total) {
$.isFunction(onComplete) && onComplete(data);
}
};
$images.each(function() {
this.onload = function() {
success++;
check(this, 'success');
};
this.onerror = function() {
error++;
check(this, 'error');
};
});
}; |
Hi,
I'm working on a mobile app and was searching for a solution to preload the "current" image when an image has the srcset attribute (for calculating it's container height).
I had many issues on chrome/win and resolved them by using the img property 'currentSrc'.
Because there was no event, when currentSrc has been set by chrome (I was testing many timeout values), I choose following approach:
When all images are "computed" by chrome I set all src properties of the resolved images to
var length = images.length;
for (var i = 0; i < length; i++) {
if (images[i].hasOwnProperty('currentSrc') && !! !images[i].currentSrc) {
images.src = images[i].currentSrc;
}
}
I'm not sure if this is a solution to the specs, but so I've got it working and imagesloaded doesn't load the wrong images initially. Imo/Hopefully only browsers, which are supporting the srcset attribute are setting img.currentSrc.
The text was updated successfully, but these errors were encountered: