본문 바로가기

자바스크립트 기기기초

#6.1 Background

const images = ["0.jpg","1.jpg","2.jpg"]; //폴더 안에 있는 이미지 이름이랑 똑같게

const chosenImage = images[Math.floor(Math.random()*images.length)];

const bgImage = document.createElement("img"); //img요소 생성

bgImage.src = `img/${chosenImage}`;

document.body.appendChild(bgImage) //body에 html추가(가장 뒤에)

'자바스크립트 기기기초' 카테고리의 다른 글

#7.1 Adding ToDos  (0) 2023.02.15
#7.0 Setup  (0) 2023.02.15
#6.0 Quotes  (0) 2023.02.13
#5.2 PadStart  (0) 2023.02.10
#5.1 Timeouts and Dates  (0) 2023.02.10