This repository has been archived by the owner on Sep 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
52 lines (45 loc) · 1.76 KB
/
script.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"use strict";
const espressoEl = document.getElementById("espresso");
const latteEl = document.getElementById("latte");
const boxes = document.querySelectorAll(".box");
const picList = document.querySelectorAll(".pics-div");
const openClosedList = [];
picList.forEach((closed) => openClosedList.push(0));
const openCloseBox = function () {
// make the span = down-arrow
// check if open or closed
// take off hidden of div under it
this.lastElementChild.textContent =
this.lastElementChild.textContent === "^" ? "˅" : "^";
this.nextElementSibling.classList.toggle("hidden");
};
for (let i = 0; i < boxes.length; i++) {
boxes[i].addEventListener("click", openCloseBox);
}
// document.querySelector("#espresso-pic").addEventListener("click", function () {
// document.querySelector("#espresso-pic").style.transform =
// "translate3d(500px, -100px, 0px)";
// document.querySelector("#espresso-pic").style.transition =
// "transform 2s ease-in-out";
// });
for (let i = 0; i < picList.length; i++) {
picList[i].addEventListener("click", function () {
if (openClosedList[i] === 0) {
openClosedList[i] = 1;
this.classList.remove("close-rightOrLeft");
this.classList.add(`open-${i % 2 === 0 ? "right" : "left"}`);
setTimeout(function () {
picList[i].firstElementChild.classList.toggle("hidden");
picList[i].firstElementChild.classList.toggle("word-typer");
}, 1900);
} else {
openClosedList[i] = 0;
this.classList.remove(`open-${i % 2 === 0 ? "right" : "left"}`);
this.classList.add("close-rightOrLeft");
setTimeout(function () {
picList[i].firstElementChild.classList.toggle("hidden");
picList[i].firstElementChild.classList.toggle("word-typer");
}, 1900);
}
});
}