dinbror / blazy

Hey, be lazy! bLazy.JS is a lightweight pure JavaScript script for lazy loading and multi-serving images. It's working in all modern browsers including IE7+.
http://dinbror.dk/blazy
MIT License
2.63k stars 356 forks source link

How to set <img> src if the source is a broken link? #122

Closed skylee91 closed 7 years ago

skylee91 commented 7 years ago

How to set src if the source is a broken link?

dinbror commented 7 years ago

Hey @skylee91

Could you please elaborate? What do you want to achieve? Do you want to set an alternative src when the actual src is broken?

skylee91 commented 7 years ago

Yes, let say the actual src is broken, can we display a Image Not Found picture to user?

dinbror commented 7 years ago

@skylee91 You can already do it today in the error callback. Something like this:

var bLazy = new Blazy({ 
        error: function(ele, msg){
            ele.src = "not-found-image.jpg"  
        }
    });

I might add it as an option to define in next release

skylee91 commented 7 years ago

Thanks. It helps a lot.