Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

img

Create an IMG element

Install

$ npm install npm-dom/img

Usage

A basic usage of it would be:

var img = require('img')
var el = img('https://avatars2.githubusercontent.com/u/7551498')
document.body.appendChild(el)

You can also pass a callback, it'll be called when the img is load or failed to load:

img('https://avatars2.githubusercontent.com/u/7551498', function (error, el) {
  // image is loaded

  error
  // => undefined

  document.body.appendChild(el)
})

To set timeout:

var img = require('img')
var timeout = require('callback-timeout')

img('loads-very-slow.gif', timeout(function (error, el) {
  error.message
  // => "Timeout"

}, 2000))

Optional crossOrigin parameter:

var img = require('img')

img('path/to/file.png', { crossOrigin: 'Anonymous' }, function(err, image) {
    console.log(image)
})

See test.js for more info.

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.