kenwheeler / slick

the last carousel you'll ever need
kenwheeler.github.io/slick
MIT License
28.55k stars 5.88k forks source link

Lazyloaded called twice with 1 slide #2520

Open kobiak opened 8 years ago

kobiak commented 8 years ago

When lazy load images, and there's one slide with infinite: false. Lazyloaded callback is fired 2 times.

It works perfectly when there're 2 slides or more.

http://codepen.io/kobiak/pen/qaagpP

Steps to reproduce the problem

  1. Just view console log.

    What is the expected behaviour?

To fire lazyloaded only once

More Details

shermendev commented 7 years ago

I am experiencing the same issue.

shermendev commented 7 years ago

This is what triggers the bug for me responsive: [{ //any code }]

morgant commented 7 years ago

I am experiencing the 'lazyLoaded'/'lazyLoadError' events being triggered multiple times, as well.

morgant commented 7 years ago

Looking at https://github.com/kenwheeler/slick/blob/master/slick/slick.js#L1616, it will nearly always (or always?) lazy load the first slide twice.

shermendev commented 7 years ago

For me, double lazy loading happens with every slide, not just the first one. If I remove 'responsive' property from the options lazyload will fire correctly.

panaak commented 6 years ago

In my case only fires twice for local images. That is for images relative to site domain. Images from external sources are loaded correctly.

Setting / unsetting responsive option had no effect.

jeznacki commented 5 years ago

It's becasue slick first create img element in JS imageToLoad = document.createElement('img');

then is listening his onload event - (when fired image is loaded first time) imageToLoad.onload = function() {

then it puts it in image src attribute in DOM (image load event two) image.attr('src', imageSource)

You should not bother to much because after first onload event image should be cached by browser so second time is just displayed from cache.

However would be nice to have it fixed.

pre2612 commented 3 years ago

Do we have solution for it?

jeznacki commented 3 years ago

Yes, ignore it.

Pon., 27 wrz 2021, 20:19 użytkownik Preethy Borrawar < @.***> napisał:

Do we have solution for it?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kenwheeler/slick/issues/2520#issuecomment-928154769, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJJJO7THFNQ4IKB7E2QIPLUECYR7ANCNFSM4CQIZFFQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

pre2612 commented 3 years ago

What is the solution could you please share having same issues