tuupola / lazyload

Vanilla JavaScript plugin for lazyloading images
https://appelsiini.net/projects/lazyload/
MIT License
8.76k stars 2.24k forks source link

Default response when image URL returns 404 #331

Open abdfahim opened 8 years ago

abdfahim commented 8 years ago

Hi,

I want the plugin to show a no image or some predefined default image when the src url returns none (404 error). Is it possible?

<img class="lazy" data-original="http://www.mydomain.com/noimage.jpg">

ngoduykhanh commented 8 years ago

I'm looking for this feature too.

Jevirs commented 8 years ago

R.I.P

Jevirs commented 8 years ago

OK,I got it.

  1. open this JS file https://github.com/tuupola/jquery_lazyload/blob/master/jquery.lazyload.js
  2. find line 129, add this .on("error", $self.attr("src","images/error.png})
  3. And it looks like .attr("src", $self.attr("data-" + settings.data_attribute)) .on("error", function() { $self.attr("src","images/error.png"); }) 4.minify the JS file and enjoy