Skip to content

Instantly share code, notes, and snippets.

@buglessir
Created December 6, 2020 07:20
Show Gist options
  • Save buglessir/9dd895dcd0b695b49387177ef83d7588 to your computer and use it in GitHub Desktop.
Save buglessir/9dd895dcd0b695b49387177ef83d7588 to your computer and use it in GitHub Desktop.
<!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 = [
'https://s.cafebazaar.ir/1/icons/com.newvoy.cookingvoyage.android_512x512.webp',
'https://s.cafebazaar.ir/1/icons/com.ccmg.deadspreadingsurvival.cb_512x512.webp',
'https://s.cafebazaar.ir/1/icons/com.balootgames.khayati_512x512.webp'
]
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