diff --git a/Invalid-src-demo.html b/Invalid-src-demo.html new file mode 100644 index 0000000..2b38329 --- /dev/null +++ b/Invalid-src-demo.html @@ -0,0 +1,149 @@ + + +
+ + + + + + +A very lightweight plugin to lazy load images for jQuery or Zepto.js
+ + + + Tweet +Compatible with All Browsers and IE7+.
+ +Download the script from the project page on GitHub.
+If you have any suggestion or bug to report please use github issues or get it touch with me on twitter - @lmgalmeida.
+ +Unveil is licensed under the MIT license.
+ + + + + diff --git a/jquery.unveil.js b/jquery.unveil.js index 8cfeb25..d962329 100644 --- a/jquery.unveil.js +++ b/jquery.unveil.js @@ -10,7 +10,7 @@ ;(function($) { - $.fn.unveil = function(threshold, callback) { + $.fn.unveil = function(threshold, callback, errorSrc) { var $w = $(window), th = threshold || 0, @@ -19,12 +19,22 @@ images = this, loaded; + this.one("unveil", function() { var source = this.getAttribute(attrib); source = source || this.getAttribute("data-src"); if (source) { this.setAttribute("src", source); if (typeof callback === "function") callback.call(this); + } else if(errorSrc){ + + this.setAttribute("src", errorSrc); + } + this.onerror = function () { + if(errorSrc) + { + this.setAttribute("src", errorSrc); + } } });