I have tried to generate 5 different random numbers in the for loop to generate the 5 images, but the 5 random numbers are generated exactly the same! var numberOfFaces = 5;
var theLeftSide = document.getElementById("leftSide");
for (var i = 0; i < numberOfFaces; i++) {
//create image
var img = document.createElement('img');
img.src = "http://ift.tt/1GzZEsa";
var random1 = Math.floor(Math.random() * 500 - (100 * i));
var random2 = Math.floor(Math.random() * 500 - 100 * i);
img.style.top = random1;
img.style.left = random2;
document.body.appendChild(img);
}
Aucun commentaire:
Enregistrer un commentaire