img-ready
Execute a callback after an image loaded.
Usage
Install
npm install img-ready
This plugin can be used as an AMD/CommonJS module. Otherwise, it will expose an imgReady
method on the global object (window
).
var img = document.getElementById('logo');
var imgUrl = 'https://assets-cdn.github.com/images/modules/logos_page/Octocat.png';
imgReady(imgUrl, {
onload: function(e) {
console.log(e);
console.log(this);
img.src = this.src;
},
onerror: function(e) {
console.log(e);
console.log('load error');
}
});
Or, a callback (onload) can be passed as the second parameter.
imgReady(imgUrl, function(e) {
console.log(e);
console.log(this);
img.src = this.src;
});
License
MIT