to make randomBackGround Image
Seongjin Park
1 min read
const images = ["0.jpeg", "1.jpeg", "2.jpeg"];
const chosenImage = images[Math.floor(Math.random()*images.length)];
const bgImage = document.createElement("img");
bgImage.src = `img/${chosenImage}`;
document.body.appendChild(bgImage);
to make random background image,
i put all the images that i want in the array.
and then using Math.random, I randomly chose index of that array.
and I manipulated DOM with using DOM.src
and put the random Image that i already prepared.
0
Subscribe to my newsletter
Read articles from Seongjin Park directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by