toddmotto / echo

Lazy-loading images with data-* attributes

Home Page:http://toddmotto.com/labs/echo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there any way to handle broken images?

AndrewEastwood opened this issue · comments

for example If this had property 'replaceBrokenImagesWith' I would set any default image to show in place of broken images.
it could be also callback function that is being invoked every time when error is occurred passing by broken image name and sets callback result into images' src attribute.

@AndrewEastwood I did that may be it can help you:

echo.init({
      offset: 1000,
      throttle: 10,
      debounce: false,
      unload: false,
      callback: function(element, op) {
        element.onerror = function() {
          var ele = element;
          var notFoundClass = 'image-404';
          if (ele.className.indexOf(notFoundClass) == -1) {
            ele.src = 'data:image/png;base64,';
            ele.className = ele.className + ' ' + notFoundClass;
          }
        }
      }
    });