flickity icon indicating copy to clipboard operation
flickity copied to clipboard

<Picture> element does not work with flickity.

Open YKehinde opened this issue 10 years ago • 36 comments

It would be amazing to feature responsive images in the slide. e.g. square images for mobile and full images for desktop. Is this already supported or something you might have thought about?

YKehinde avatar Jun 15 '15 10:06 YKehinde

Thanks for this feature request. Add a 👍 reaction to this issue if you would like to see Flickity add support for <picture> for lazyLoad or imagesLoaded. Do not add +1 comments — they will be deleted

desandro avatar Jun 15 '15 12:06 desandro

+1

YKehinde avatar Jun 15 '15 14:06 YKehinde

+1

rentorm avatar Jun 16 '15 11:06 rentorm

+1

CiaranPark avatar Jun 16 '15 14:06 CiaranPark

+1. Some hopefully helpful numbers: Picture support is currently at 45% global. Safari 9 is support still TBD, but srcset/sizes have been in nightlies for awhile. IE Edge supports srcset with density descriptors, and <picture> support is under consideration, which in this case means it is on the roadmap. In the meantime there's the Picturefill polyfill. This is ready for production use.

albell avatar Jun 17 '15 16:06 albell

+1

eikeco avatar Jul 29 '15 14:07 eikeco

+1

ritchieanesco avatar Aug 11 '15 10:08 ritchieanesco

+1

florentb avatar Sep 15 '15 12:09 florentb

+1

mhokane avatar Sep 15 '15 22:09 mhokane

+1

raywongjr avatar Sep 16 '15 17:09 raywongjr

+1

sambaldwin avatar Oct 01 '15 16:10 sambaldwin

+1

pinich avatar Nov 11 '15 09:11 pinich

+1

downFast avatar Mar 03 '16 12:03 downFast

+1

Chriz74 avatar Mar 15 '16 12:03 Chriz74

+1

danjayrose avatar Apr 13 '16 10:04 danjayrose

+1

spacecat avatar May 23 '16 19:05 spacecat

+1. It's sad to see that almost a year later this is still not a thing, especially as browser support is getting better even without polyfill.

LostKobrakai avatar Jun 10 '16 08:06 LostKobrakai

It's sad to see that almost a year later this is still not a thing

The past year has been very un-sad for Flickity and Metafizzy in general. I realize it can be a bummer when the one issue you're looking for is unresolved. Please consider the larger picture.

desandro avatar Jun 10 '16 11:06 desandro

@marzepani see https://github.com/metafizzy/flickity/issues/172 for srcset

raywongjr avatar Jan 27 '17 19:01 raywongjr

So, one year later, is this coming in v2? Not trolling, it's a serious question.

eheiser avatar Aug 11 '17 13:08 eheiser

Sorry no plans to support this feature currently. <picture> is not supported by Internet Explorer or Android 4. But I may decide to take this on later.

desandro avatar Aug 11 '17 14:08 desandro

Cheers man, making due with the lazyload feature to speed things up instead. Awesome work all around!

eheiser avatar Aug 11 '17 14:08 eheiser

<div class="main-carousel">
  <picture>
    <source srcset="x-wide.png" media="(min-width: 600px)">
    <img class="carousel-cell" src="x-narrow.png">
  </picture>
  <picture>
    <source srcset="y-wide.png" media="(min-width: 600px)">
    <img class="carousel-cell" src="y-narrow.png">
  </picture>
</div>
const flkty = new Flickity( '.main-carousel', {
  cellSelector: '.carousel-cell'
});

It worked, sort of.

ItangSanjana avatar Dec 20 '17 13:12 ItangSanjana

I'd be keen to see this implemented, as I'd like to able to make webp images available where the browser supports, and for that I'd need to use <picture>.

drewm avatar Jul 10 '18 13:07 drewm

Hi, Flickity is great and I really like it. Isn't it time to reconsider this feature request? It's almost end of 2018 and Internet Explorer is almost a thing of past now. Like @drewm I'd like to use webp images too as well as lazy loading.

ozguruysal avatar Sep 04 '18 22:09 ozguruysal

Thanks why I'm here, I just saw this Ticket is much newer so I just want to connect my POST which I just made some mins ago to here.

I think its not much to do to achive a fully integrates <picture> lazyloading. It almost works, just data-flickity-lazyload-srcset have to be replaced inside <source> tags! Would love to see this feature!!!

the-hotmann avatar May 18 '19 10:05 the-hotmann

I think the best solution to this would be: using the <template> TAG! (like described here LINK)

The good part about it: it can lazyLoad the whole <picture> TAG at once, not like other solutions just all images inside it.

Would look like this:

<template class="slickity-lazy">
    <source srcset="https://dummyimage.com/2560x1440 1x, https://dummyimage.com/5120x2880 2x" media="(min-height: 1440px)">
    <source srcset="https://dummyimage.com/1280x960 1x, https://dummyimage.com/2560x1920 2x" media="(min-height: 960px)">
    <source srcset="https://dummyimage.com/640x480 1x, https://dummyimage.com/1280x960 2x" media="(min-height: 0px)">
    <img src="https://dummyimage.com/4000x3000">
</template>

The TAG-Name just have to be replaced when ever you want to load its content!

I just made it! <template> in the source-code but made it work with JS

Here is my DEMO - (change height to see its working) Selfhosted, so may not online for years

the-hotmann avatar May 18 '19 11:05 the-hotmann

@desandro may you have a look at this. Would be awesome if you could implement this into Slickity as I use it with <picture> tag and it cant lazyLoad..

the-hotmann avatar May 18 '19 12:05 the-hotmann

I just made another DEMO which works with vanilla JavaScript and DeepCopy.

DEMO 1: LINK DEMO 2: LINK

Both now also have a delay in the function of 500ms to make it more visible to the eye and better noticeable in the Dev-Console under Network. I personaly like DEMO 2 more. But both of them require a html like this:

<div class="carousel-wrapper">
    <div class="carousel carousel-main">
        <picture>
            <source srcset="https://dummyimage.com/2560x1440 1x, https://dummyimage.com/5120x2880 2x" media="(min-height: 1440px)">
            <source srcset="https://dummyimage.com/1280x960 1x, https://dummyimage.com/2560x1920 2x" media="(min-height: 960px)">
            <source srcset="https://dummyimage.com/640x480 1x, https://dummyimage.com/1280x960 2x" media="(min-height: 0px)">
            <img src="https://dummyimage.com/4000x3000">
        </picture>
        <picture>
            <source srcset="https://dummyimage.com/2560x1440 1x, https://dummyimage.com/5120x2880 2x" media="(min-height: 1440px)">
            <source srcset="https://dummyimage.com/1280x960 1x, https://dummyimage.com/2560x1920 2x" media="(min-height: 960px)">
            <source srcset="https://dummyimage.com/640x480 1x, https://dummyimage.com/1280x960 2x" media="(min-height: 0px)">
            <img src="https://dummyimage.com/4000x3000">
        </picture>
        <template id="slickity-lazy">
            <source srcset="https://dummyimage.com/2560x1440 1x, https://dummyimage.com/5120x2880 2x" media="(min-height: 1440px)">
            <source srcset="https://dummyimage.com/1280x960 1x, https://dummyimage.com/2560x1920 2x" media="(min-height: 960px)">
            <source srcset="https://dummyimage.com/640x480 1x, https://dummyimage.com/1280x960 2x" media="(min-height: 0px)">
            <img src="https://dummyimage.com/4000x3000">
        </template>
        <template id="slickity-lazy">
            <source srcset="https://dummyimage.com/2560x1440 1x, https://dummyimage.com/5120x2880 2x" media="(min-height: 1440px)">
            <source srcset="https://dummyimage.com/1280x960 1x, https://dummyimage.com/2560x1920 2x" media="(min-height: 960px)">
            <source srcset="https://dummyimage.com/640x480 1x, https://dummyimage.com/1280x960 2x" media="(min-height: 0px)">
            <img src="https://dummyimage.com/4000x3000">
        </template>
        <template id="slickity-lazy">
            <source srcset="https://dummyimage.com/2560x1440 1x, https://dummyimage.com/5120x2880 2x" media="(min-height: 1440px)">
            <source srcset="https://dummyimage.com/1280x960 1x, https://dummyimage.com/2560x1920 2x" media="(min-height: 960px)">
            <source srcset="https://dummyimage.com/640x480 1x, https://dummyimage.com/1280x960 2x" media="(min-height: 0px)">
            <img src="https://dummyimage.com/4000x3000">
        </template>
    </div>
</div>

Notice: the DOM/HTML now decides what and how many are lazyloaded, not "lazyLoad": 2 anymore..

Now the first two are getting loaded instantly and the other should get converted short befor coming to the viewport. At least thats how I think it would work. ANd yes I know IDs should be unique, we can change them to classes but for the demo its working

the-hotmann avatar May 18 '19 23:05 the-hotmann

With WebP browser support now > 50% US and > 80% global, and file size savings in the neighborhood of 30% compared to lossy JPEG, Google is increasingly pushing for use of WebP in its site auditing tools. (See https://developers.google.com/speed/pagespeed/insights/?url=https%3A%2F%2Fflickity.metafizzy.co under "Serve images in next-gen formats".)

I'm sure none of this is news to you @desandro, but I'm currently wrestling with how to to improve some site audit scores on a site that uses Flickity everywhere (I originally built the site and am very vocal in my support for this wonderful library!) yet when it came time for a different developer to add a slider around a set of massive hero images that use <picture> for art direction and WebP support, they instead used a different slider plugin, since Flickity does not support picture. As a result, the site has two different slider plugins running. 🙃

I saw the old issue (#172) where the writer/maintainer of Lazysizes (@afarkas — another excellent project!) helpfully chimed in on a combo method for using it with Flickity, but his demos aren't up-to-date with Flickity v2 and no longer work.

The Chrome team is working on browser-native image lazyloading, but the feature remains behind an Experimental Feature flag.

I know that I have some options between Lazysizes and several of the comments/suggestions above, but I'm writing all this out to ask for at least a recommended way forward to be documented for Flickity. Thank you for your consideration. 🙇

kbav avatar Aug 06 '19 20:08 kbav