-
Notifications
You must be signed in to change notification settings - Fork 219
/
main.js
156 lines (135 loc) · 4.76 KB
/
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
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const reviewWrap = document.getElementById("reviewWrap");
const leftArrow = document.getElementById("leftArrow");
const rightArrow = document.getElementById("rightArrow");
const imgDiv = document.getElementById("imgDiv");
const personName = document.getElementById("personName");
const profession = document.getElementById("profession");
const description = document.getElementById("description");
const surpriseMeBtn = document.getElementById("surpriseMeBtn");
const chicken = document.querySelector(".chicken");
let isChickenVisible;
let people = [
{
photo:
'url("https://cdn.pixabay.com/photo/2018/03/06/22/57/portrait-3204843_960_720.jpg")',
name: "Stefina hussein",
profession: "Delhi",
description:
"Booking train tickets used to be a hassle for me, but not anymore! Ticket-Booking has made it so easy and convenient to secure my tickets. The real-time availability feature helped me plan my journey without any worries. Highly recommend it for stress-free bookings." },
{
photo:
"url('https://cdn.pixabay.com/photo/2019/02/11/20/20/woman-3990680_960_720.jpg')",
name: "Celina Cassandra",
profession: "Allepi",
description:
"I had to sell my bus ticket last minute, and Ticket-Booking’s platform made it incredibly easy. Within minutes, I had an offer, and the transaction was smooth. The customer service was very responsive, and I felt confident using the service. This platform is a lifesaver!" },
{
photo:
"url('https://cdn.pixabay.com/photo/2016/11/21/12/42/beard-1845166_960_720.jpg')",
name: "Gellaso Giano",
profession: "Goa",
description:
"Ticket-Booking has taken all the stress out of booking tickets. Whether it's for a quick bus trip or a cross-country train ride, this platform has me covered. Real-time availability is such a game changer!" },
{
photo:
"url('https://cdn.pixabay.com/photo/2014/10/30/17/32/boy-509488_960_720.jpg')",
name: "Afzal Khan",
profession: "Hyderabad",
description:
"I’ve been using Ticket-Booking for both bus and train tickets for the past few months, and it has always been a fantastic experience. The website is fast, reliable, and super easy to use. I also appreciate the helpful customer support team who resolved my issue within minutes." }
];
imgDiv.style.backgroundImage = people[0].photo;
personName.innerText = people[0].name;
profession.innerText = people[0].profession;
description.innerText = people[0].description;
let currentPerson = 0;
//Select the side where you want to slide
function slide(whichSide, personNumber) {
let reviewWrapWidth = reviewWrap.offsetWidth + "px";
let descriptionHeight = description.offsetHeight + "px";
//(+ or -)
let side1symbol = whichSide === "left" ? "" : "-";
let side2symbol = whichSide === "left" ? "-" : "";
let tl = gsap.timeline();
if (isChickenVisible) {
tl.to(chicken, {
duration: 0.4,
opacity: 0
});
}
tl.to(reviewWrap, {
duration: 0.4,
opacity: 0,
translateX: `${side1symbol + reviewWrapWidth}`
});
tl.to(reviewWrap, {
duration: 0,
translateX: `${side2symbol + reviewWrapWidth}`
});
setTimeout(() => {
imgDiv.style.backgroundImage = people[personNumber].photo;
}, 300);
setTimeout(() => {
description.style.height = descriptionHeight;
}, 300);
setTimeout(() => {
personName.innerText = people[personNumber].name;
}, 300);
setTimeout(() => {
profession.innerText = people[personNumber].profession;
}, 300);
setTimeout(() => {
description.innerText = people[personNumber].description;
}, 300);
tl.to(reviewWrap, {
duration: 0.4,
opacity: 1,
translateX: 0
});
if (isChickenVisible) {
tl.to(chicken, {
duration: 0.4,
opacity: 1
});
}
}
function setNextCardLeft() {
if (currentPerson === 3) {
currentPerson = 0;
slide("left", currentPerson);
} else {
currentPerson++;
}
slide("left", currentPerson);
}
function setNextCardRight() {
if (currentPerson === 0) {
currentPerson = 3;
slide("right", currentPerson);
} else {
currentPerson--;
}
slide("right", currentPerson);
}
leftArrow.addEventListener("click", setNextCardLeft);
rightArrow.addEventListener("click", setNextCardRight);
surpriseMeBtn.addEventListener("click", () => {
if (chicken.style.opacity === "0") {
chicken.style.opacity = "1";
imgDiv.classList.add("move-head");
surpriseMeBtn.innerText = "Remove the chicken";
surpriseMeBtn.classList.remove("surprise-me-btn");
surpriseMeBtn.classList.add("hide-chicken-btn");
isChickenVisible = true;
} else if (chicken.style.opacity === "1") {
chicken.style.opacity = "0";
imgDiv.classList.remove("move-head");
surpriseMeBtn.innerText = "Surprise me";
surpriseMeBtn.classList.add("surprise-me-btn");
surpriseMeBtn.classList.remove("hide-chicken-btn");
isChickenVisible = false;
}
});
window.addEventListener("resize", () => {
description.style.height = "100%";
});