From 372698e849282ccb80315cddd5a53f0eac095b5a Mon Sep 17 00:00:00 2001 From: jun_tanaka555 Date: Tue, 23 Jan 2018 00:29:13 +0900 Subject: [PATCH] implement callback function feature --- README.md | 10 ++++++++++ lazyload.js | 3 +++ 2 files changed, 13 insertions(+) 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 + ")"; }