Socket
Socket
Sign inDemoInstall

img-ready

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    img-ready

Execute a callback after an image loaded


Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Install size
7.11 kB
Created
Weekly downloads
 

Readme

Source

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

FAQs

Last updated on 19 Jun 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc