diff --git a/README.md b/README.md index a3e4e400..688036af 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,16 @@ With the HTML in place you can then initialize the plugin using the factory meth lazyload(); ``` +If you prefer you can pass callback function. When the image is loaded, the function defined as 'onLoadCallback' is called. + +```js +lazyload(null, { + onLoadCallback: function() { + console.log('callback function is called!'); + } +}); +``` + If you prefer you can explicitly pass the image elements to the factory. Use this for example if you use different class name. ```js diff --git a/lazyload.js b/lazyload.js index fc7fdf7c..d3a7742d 100644 --- a/lazyload.js +++ b/lazyload.js @@ -110,6 +110,9 @@ if (srcset) { entry.target.srcset = srcset; } + if(self.settings.onLoadCallback) { + entry.target.onload = self.settings.onLoadCallback; + } } else { entry.target.style.backgroundImage = "url(" + src + ")"; }