// Array of images to load.
const images = [
"path/to/image.extension",
"/images/someimage.png",
"./images/anotherimage.jpg",
"../separatefolder/assets/onelastimage.gif"
];
// Function to load an image.
function loadImage(src) {
return new Promise(function(res, rej) {
const image = new Image();
function loadCallback() {
image.removeEventListener("load", loadCallback);
image.removeEventListener("error", errorCallback);
res(image);
}
function errorCallback() {
image.removeEventListener("load", loadCallback);
image.removeEventListener("error", errorCallback);
rej(image);
}
image.addEventListener("load", loadCallback);
image.addEventListener("error", errorCallback);
image.src = src;
});
}
// Function to load multiple images.
function loadImages(...srcs) {
const promises = [];
for (let i = 0; i < srcs.length; i++) {
promises.push(loadImage(srcs[i]));
}
return Promise.all(promises);
}
// Load the images in the images array and print them to the console.
loadImages(...images).then(console.log);
for(let i = 0; i < 10; i++) {
const img = document.createElement("img");
img.src = "https://picsum.photos/200/301";
}
function placeImage(x)
{
var div = document.getElementById("div_picture_right");
div.innerHTML = ""; // clear images
for (counter=1;counter<=x;counter++) {
var imagem=document.createElement("img");
imagem.src="borboleta/Borboleta"+counter+".png";
div.appendChild(imagem);
}
}
window.onload = function() {
placeImage(48);
};
function placeImage(x)
{
var div = document.getElementById("div_picture_right");
div.innerHTML = ""; // clear images
for (counter=1;counter<=x;counter++) {
var imagem=document.createElement("img");
imagem.src="borboleta/Borboleta"+counter+".png";
div.appendChild(imagem);
}
}
window.onload = function() {
placeImage(48);
};