-
Notifications
You must be signed in to change notification settings - Fork 602
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
lazyLoad srcset or <picture> #172
Comments
Thanks for this feature request. Add a 👍 reaction to this issue if you would like to see this feature added. |
Hi Dave, thanks for your reply. I think these are two different things. When the That’s why the srcset attribute can also be used in the <picture>
<source srcset="img-landscape-100.png 100w, img-landscape-200.png 200w" media="(orientation: landscape)">
<source srcset="img-portrait-100.png 100w, img-portrait-200.png 200w" media="(orientation: portrait)">
<img src="img.png" alt="Image">
</picture> I hope this is correctly described. I would be happy about the lazyLoad srcset attribute for the |
As I mentioned in #175 I really don't feel srcset's are the way forward. Way, way too unsupported. http://caniuse.com/#search=srcset -1. |
+1 for future friendliness. |
+1 for this 👍 I'm working right now on a website where I need high quality images, especially for retina screens, but this makes a huge overhead for non-retina visitors. Right now I'm loading all images in low quality like before, and add a data attribute with high quality retina image. Right before initializing flickity I'm checking pixelDensityRation and window size, if it's "huge enough" I'm moving retina images to flickity-lazyload. Using this approach I can show slide images even before javascripts loads and flickity is initialized 💃 However I'm not very happy with it. |
+1 This would be an incredible addition. I have a couple of carousels with a variety of photos, and the strain is too much. LazyLoad with srcset or picture would be great if it can somehow be implemented. |
+1 from me! I know Flickity uses a data-flickity-lazyload attribute for lazy loading. If we're worried about current support for picture and srcset, would a short-term solution like a data-flickity-lazyload-retina attribute be useful? I'm using Unveil.js for a project, and that one works along those lines: one data attribute for the normal image, and a second for a high-res one. http://luis-almeida.github.io/unveil/ From what I gather, not too dissimilar from what nvartolomei above tried, but it would be a Flickity option. |
+1 |
You guys know, that you can use flickity already with lazySizes to get lazyloading support for |
@aFarkas Thanks for chiming in. Can I get your expertise? I'd rather defer to lazySizes than build more logic into Flickity. From what I understand of lazySizes's behavior, it works by loading assets according to scroll Y position. With Flickity's carousels, all cells have the same scroll Y position, so they'd all get loaded at the same time. Ideally, cell assets should only be loaded when they are visible. To use lazySizes in this manner, looks like you'd set |
While this would work, I wouldn't do anything with the lazySizes API. lazySizes is a full automatic lazyloader. Here is a demo with Flickity. While lazySizes checks whether an image is inside of the viewport (+ some extra offset (called lazySizes uses several techniques to automatically detect visibility changes, so you really don't need to call anything with lazySizes. (Of course developers can tweak some parameters, like the The only thing, that needs to be done, is that flickity must update its layout as soon as an image.onload event happens, because this might change the layout also. From my viewpoint this also fixes your picture support problem. (#161) Here is some code that should work just fine in all browsers but IE8. (function(){
var oldFlickityCreate = window.Flickity.prototype._create;
window.Flickity.prototype._create = function(){
var that = this;
if(this.element.addEventListener){
this.element.addEventListener('load', function(){
that.onresize();
}, true);
}
this._create = oldFlickityCreate;
return oldFlickityCreate.apply(this, arguments);
};
})(); This approach above obviously doesn't give you 100% control over when an image is transformed and which images are transformed. Everything is handled automatically based on the viewport, the expand option and sometimes the overflow area. In case you want really 100% control. The following thing would be easier, than using You simple write the respimage markup using Here is a simple demo of this API: http://jsfiddle.net/trixta/zdqfy9mu/ But as said above, I would claim, that the configurable automatic detection in lazySizes should be good enough for 99% of all use cases. |
I'm trying to use Flickity/lazySizes together with srcset and can't quite figure it out. I've got a carousel that takes up the entire width of the window, and I only want 1 image to be loaded on page load (due to the size of the images), and then each subsequent image loaded when requested by the user. I'm initializing Flickity in my js, because I'm using a bit of js to randomize the Is there a way through Thanks! |
Lazysizes is a general lazyloader so it can't give you fine grained flickity specific control. In general you shouldn't need so much fine grained control. (I would be fine if sometimes also two images are loaded.) If lazysiizes detects that a lot of images are loading or before onload it adjusts its loading mode so that only in view images are loaded to get a fast performance. For loading just one image per slide the expand and the expFactor option can be used. For example: expand = 200 and expFactor = 1.5 In case you have multiple loads before onload. This might happen because flickity has not initialized and all cells are technically in viewport. You can solve this multiple ways. For example you can hide all cells but the first using visibility: hidden using the nth-child selector until flickity has fully initialized itself. Also loadMode = 1 might help. In case you want 100% control you can set the expand to 1 and dynamically add the class lazypreload to the images you want to load, but I think this might be too much work for tje outcome. I might put a demo together in the future. |
@aFarkas thanks for your response. I'd love to see your take on managing the loading 100%! |
@johjacb Here is also the issue tracker: |
@aFarkas Thank you for your insightful response. This is great news. I'll be working on incorporating LazySizes to the Flickity docs. |
+1 would be great to have the best method documented in the Flickity docs :) |
I am trying to open an image in a new window and load the correct image based on srcset in order to open the right image size based on resolution. ideally I would like to use photoswipe tho * but for now I am trying to achieve a simple correct image opening I am doing this:
The above doesn't open different images based on resolutions but this https://farm4.staticflickr.com/3059/2835191823_e3636abb34_m.jpg I believe is because of $str[0]; yet I have tried not to insert an index [0] and that takes me to a not found image Example: http://codepen.io/aFarkas/pen/OVoavw |
+1 |
@downFast while this is not related to Flickity, what you're looking for is currentSrc. Something like this:
|
It is related to flickity as fullscreen functionity is another open topic and a feature request if you follow up. People have applied and provided solutions in regards too, check it around flickity issues on git. Said that Thanks a lot, i will try this out as i can and i'll get back to you. Cheers :) |
@aFarkas @desandro thanks a lot for your code but in safari doesn't work, the browser is picking up only the small image size in the gallery, any help please?
|
@aFarkas @desandro I've removed the This is the full code, notice I am also using bootstrap modal for an img popup:
|
+1 flickity + lazysizes sounds like a good idea. Hope to see an updated docs version soon with an example of how to use flickity with lazysizes together with |
Hi Folks, I think I've got a pretty elegant solution going on.
Step 1: Add
Step 2: Add Modernizr's Step 3: Overwrite
Step 4: Update your markup with the new data attributes. ...something similar to PHP example below.
|
Hi @davidhellmann, did you see this comment by @aFarkas . I think you need to resize your carousel when an image is loaded. Not when the window is loaded. He also made a demo. Your code seems to be for the height bug from issue #205. The resize() executes just once after the window is loaded not when an image is lazyloaded. |
check for data-flickity-lazyload-srcset check for data-flickity-lazyload-src ✅ test & sandbox lazyload srcset For #172
🎉 Flickity v2.1.0 has been released with all new support for
<img class="carousel-cell-image"
data-flickity-lazyload-srcset="
walrus-large.jpg 720w,
walrus-med.jpg 360w"
sizes="(min-width: 1024px) 720px, 360px"
data-flickity-lazyload-src="walrus-large.jpg"
/> I'm delighted to finally ship this feature. I'm now closing this issue. For |
Very nice. This will speed things up for sure. Thanks for the effort! |
Hi and thank you for this nice slider! For me this problem is not solved. For me my html looks like this:
just /img/picture.jpg gets loaded! No matter which resolution The lazyLoading itself works, but it does not "activate" the ''. With this LazyLoading the So this does not work for If I just replace "source" with "img" then it looks like this:
these images gets ALL loaded: Now it just loads the Images in the Viewport but ALL (all resolutions). @desandro do you think you can fix this? Thanks in advance! #EDIT: I think I made it.. will share my code soon! #EDIT2: PLS watch HERE for my demo |
It would be great if there is an option to fill the "srcset" attribute instead of the "src" attribute for responsive lazy load images. Or both with a new data attribute for the srcset image array.
The text was updated successfully, but these errors were encountered: