-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Event after picturefill is finished switching the images? #664
Comments
Have you tried |
What exactly do you mean? $("img").on("load" ...) ? |
@katerlouis Yeah, that event should be emitted when an image is loaded |
But that is not exactly my what I want– It would be way cleaner if picturefill would fire an event when it's done. Let's do one! :) |
@katerlouis You can also see some discussion about possible workarounds here: The pattern I describe there would look something like this with the swiper plugin: $('.swiper').each(function(){
var swiper = new Swiper(this, {
speed: 400,
spaceBetween: 100
});
var update = function(){
//less obtrusive: swiper.updateContainerSize();
swiper.update();
};
this.addEventListener('load', update, true);
}); |
I use Safari 9.1.1. The workaround looks nice; |
It fully supports responsive images. see http://caniuse.com/#search=picture
Swiper does not take a special image height, swiper tries to wait until the image(s) are loaded and then re-calculates the height of the swiper cells. For this task: Swiper seems to only handle I wouldn't use this technique anymore.
Most sliders produce reflows and swiper does this also. The JS workaround above will also additionally produce reflows, if you want to minimize reflows you need to solve this with CSS. In case of |
Thank you guys for the detailed information on that matter. You say my Safari supports picture. Every source inside one slider has the exact same dimensions. And still you say that swiper could cause a reflow there? I don't understand that– yes: swiper waits fo all the images to load; but as said they have the same dimensions. Why would the initial slide be the height of the (assumingly) phone images dimension? Could this have to do something with the lack of an src-attribute in my markup? I only use srcset on the img-tag inside the picture-tagg, like picturefill suggests. |
Maybe try adding to the
|
I use responsive images inside a slider created with swiper.
http://idangero.us/swiper/#.V5o4f1dshE4
This plugin calculates the height for the first shown element and then has a "autoHeight" option for the next slides to come. Pretty cool.
I like art direction and therefore have different heights on my responsive images.
The fallback / default for instance in most cases is a 17:15 aspect ratio. The image gets wider with higher viewport.
Problem now:
Swiper calculates the height with the initial aspect ratio of the phone image.
After swiper got its height picturefill.js switches out the image.
Strange is: roughly 8 of 10 times picturefill.js is faster than swiper and the problem doesn't occur.
But those 20% are worth recalculating after picturefill is finished.
My question:
How can I execute code after picturefill has done its thing?
PS: I'm open to suggestions for different solutions.
The text was updated successfully, but these errors were encountered: