Encapsulate fallback behavior when images fail to load. Works with Zepto.js as well. :)
Call $('.foo').fallback
on an image selector to fallback to another image if the
main image fails to load.
There are two ways to use it.
- Specify a fallback image URL
$('img.photo').fallback('http://google.com/fallback.jpg');
- Specify a callback function:
$('.photo-container > img').fallback(function () {
$('.photo-container').hide();
}).attr('src', 'http://my.photosite.com/image1.jpg');