Skip to content

Instantly share code, notes, and snippets.

@IPRIT
Last active May 11, 2018 12:19
Show Gist options
  • Select an option

  • Save IPRIT/9ea5273a7865c75f41d87d773df37844 to your computer and use it in GitHub Desktop.

Select an option

Save IPRIT/9ea5273a7865c75f41d87d773df37844 to your computer and use it in GitHub Desktop.
function loadImage (url) {
return new Promise((resolve, reject) => {
let img = new Image();
img.addEventListener('load', _ => {
resolve(img)
});
img.addEventListener('error', _ => {
reject(_)
});
img.src = url;
});
}
loadImage('https://yastatic.net/www/_/x/Q/xk8YidkhGjIGOrFm_dL5781YA.svg').then(img => {
document.body.appendChild( img );
}).catch( console.log );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment