jQuery plugin to detect and replace broken or slow-loading images
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.markdown
bower.json
brokenimage.jquery.json
jquery.brokenimage.js
test.html

README.markdown

brokenImage: a jQuery plugin

brokenImage is a jQuery plugin that is able to detect and replace images that are either broken or are taking a long time to load. If no replacement image is specified then the CSS visibility is set to hidden.

Usage

Fix a broken Image object:

  var image = new Image();
  image.src = '/might/be/broken.png';
  image.brokenImage();

Fix a broken image tag:

  <img src="/might/be/broken.png" alt="Might be broken" id="myImage" />

  $('#myImage').brokenImage();

Fix a collection of images:

  <div id="myImages">
    <img src="/might/be/broken" alt="Might be broken" />
    <img src="/might/also/be/broken" alt="Might also be broken" />
  </div>

  $('#myImages img').brokenImage();

Set a custom image replacement instead of setting the visibility to hidden:

  image.brokenImage({replacement: '/images/placeholder.png'});

Set a custom timeout to override the 5 second default:

  image.brokenImage({timeout: 100}); // 100 ms

Licensing

Licensed under the MIT: http://www.opensource.org/licenses/mit-license.php

Copyright (c) 2011 Stateless Systems (http://statelesssystems.com)