Created
December 6, 2020 07:46
-
-
Save buglessir/63f63488777f875f47103692f5ea97f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
<style> | |
img{ | |
width: 150px; | |
height: auto; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="container"></div> | |
<script> | |
var container = document.getElementById('container'); | |
var images_url = ['Image_URL_ONE', 'Image_URL_TWO', 'Image_URL_THREE', /* other URLs... */]; | |
function loadImageByPromise(url) { | |
return new Promise(function(resolve) { | |
let img = document.createElement('img'); | |
img.src = url; | |
img.onload = function() { | |
resolve(img); | |
} | |
}); | |
} | |
(async function() { | |
for (var url of images_url) { | |
var img = await loadImageByPromise(url); | |
container.appendChild(img); | |
} | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment