Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript load multiple images

// 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);
Comment

add multiple images inside the DOM js


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);
};

Comment

upload multiple images node js

multiple images node 
Comment

add multiple images inside the DOM js

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);
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: sum of a sequence 
Javascript :: root of any number javascript 
Javascript :: create a node 
Javascript :: mdn javascript 
Javascript :: loop for of 
Javascript :: remove item from array 
Javascript :: code cat 
Javascript :: find the length and the last character of string in js 
Javascript :: discord js role giver 
Javascript :: jquery datepicker disable dates dynamically 
Javascript :: react validate 
Javascript :: window open method for browser detection 
Javascript :: como agregar items en un array javascript 
Javascript :: npm passport-instagram 
Javascript :: signalr 
Javascript :: javascript free code editors 
Javascript :: how to create module in react 
Javascript :: array reverse with for loop 
Javascript :: Beep sound Javascript 
Javascript :: uploading json data to s3 bucket in node js 
Javascript :: formidable form node js 
Javascript :: const justCoolStuff = (arr1, arr2) = arr1.filter(item = arr2.includes(item)); 
Python :: abc list python 
Python :: python open link in browser 
Python :: seaborn figure size 
Python :: how many nan in array python 
Python :: get terminal size python 
Python :: blink raspberry pico 
Python :: python if main 
Python :: tensorflow version check 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =