-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
27 lines (24 loc) · 777 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const mainArea = document.querySelector("#main");
for (let i = 0; i < data.length; i++) {
let item = data[i];
let newItem = document.createElement("span");
newItem.classList.add("item");
newItem.setAttribute("id", `${data.indexOf(item)}`);
i == data.length - 1
? (newItem.innerText = `and ${item.alt}.`)
: (newItem.innerText = `${item.alt}, `);
mainArea.appendChild(newItem);
}
const items = document.querySelectorAll(".item");
const bgImg = document.querySelector("#bgImg");
items.forEach((item) => {
item.addEventListener("mouseover", () => {
item.classList.add("active");
let src = data[item.id].src;
bgImg.src = src;
});
item.addEventListener("mouseleave", () => {
item.classList.remove("active");
bgImg.src = "";
});
});