Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement callback function feature #407

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lazyload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ")";
}
Expand Down