metafizzy / flickity

:leaves: Touch, responsive, flickable carousels
https://flickity.metafizzy.co
7.53k stars 602 forks source link

data-flickity-lazyload-srcset without data-flickity-lazyload-src #1097

Open kajman-cz opened 4 years ago

kajman-cz commented 4 years ago

If I prefer to set the srcset only by lazyLoad, the src attribute is set to null. Old browsers without srcset support will then not display the image. I must always set the data-flickity-lazyload-src attribute.

Test case: https://codepen.io/kajman-cz/pen/bGpwyEw

Looks like you just have to adjust

  // set src & serset
  this.img.src = src;

to

  // set src & srcset
  if ( src ) {
    this.img.src = src;
  }
desandro commented 3 years ago

Thank you for this feature request. Add a 👍 reaction to this issue if you would like to see this feature added. Do not add +1 comments — They will be deleted.

kajman-cz commented 3 years ago

In this function (LazyLoader.prototype.load) I would also welcome a test for img attribute loading. And if the value is "lazy", then change it to "eager" or remove this attribute.

if ( this.img.getAttribute('loading')=='lazy' ) {
    this.img.removeAttribute('loading');
}