Skip to content

Alex1990/img-ready

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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); // `e` is load event object
    console.log(this); // `this` is an Image object
    img.src = this.src;
  },
  onerror: function(e) {
    console.log(e); // `e` is error event object
    console.log('load error');
  }
});

Or, a callback (onload) can be passed as the second parameter.

imgReady(imgUrl, function(e) {
  console.log(e); // `e` is load event object
  console.log(this); // `this` is an Image object
  img.src = this.src;
});

License

MIT

About

Execute a callback after an image loaded.

Resources

License

Stars

Watchers

Forks

Packages

No packages published