-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
260 lines (255 loc) · 7.91 KB
/
app.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
let controller;
let slideScene;
let pageScene;
let projectScene;
let mouse = document.querySelector(".cursor");
let mouseTxt = mouse.querySelector("span");
let burger = document.querySelector(".burger");
let skillsBtn = document.querySelector(".skills-btn");
let popup = document.querySelector(".popup-back");
let closePopup = document.querySelector(".close-popup");
//animation Function
function animateSlides() {
//initalise controller
controller = new ScrollMagic.Controller();
//selecting elements
let sliders = document.querySelectorAll(".slide");
const nav = document.querySelector(".nav-header");
//looping over each slide
sliders.forEach((slide, index, slides) => {
const revealImg = slide.querySelector(".reveal-img");
const img = slide.querySelector("img");
const revealText = slide.querySelector(".reveal-text");
//gsap for each slide
//creating gsap timeline
const slideTl = gsap.timeline({
defaults: { duration: 1, ease: "power2.inOut" },
});
slideTl.fromTo(revealImg, { x: "0%" }, { x: "100%" });
slideTl.fromTo(img, { scale: 2 }, { scale: 1 }, "-=1");
slideTl.fromTo(revealText, { x: "0%" }, { x: "100%" }, "-=0.75");
slideTl.fromTo(nav, { y: "100%" }, { y: "0%" }, "-= 0.5");
//creating scene
slideScene = new ScrollMagic.Scene({
triggerElement: slide,
triggerHook: 0.25,
reverse: false,
})
.setTween(slideTl)
// .addIndicators({
// colorStart: "white",
// colorTrigger: "white",
// name: "slide",
// })
.addTo(controller);
//new animation
let pageTl = gsap.timeline();
//making a new variable to delay our animation
let nextSlide = slides.length - 1 === index ? "end" : slides[index + 1];
//pushing next slide by 50%
pageTl.fromTo(nextSlide, { y: "0%" }, { y: "50%" });
pageTl.fromTo(slide, { opacity: 1, scale: 1 }, { opacity: 0, scale: 0.5 });
//reversing the push for next slide to comeUp
pageTl.fromTo(nextSlide, { y: "50%" }, { y: "0%" }, "-=0.5");
pageScene = new ScrollMagic.Scene({
triggerElement: slide,
duration: "100%",
triggerHook: 0,
})
.setTween(pageTl)
//setPin will make our content stuck to the page
//pushfollowers is here false because we want our slides to wrap up again and again on scrolling
.setPin(slide, { pushFollowers: false })
// .addIndicators({
// colorStart: "white",
// colorTrigger: "white",
// name: "page",
// indent: 200,
// })
.addTo(controller);
});
}
function cursor(e) {
mouse.style.top = e.pageY + "px";
mouse.style.left = e.pageX + "px";
}
function activeCursor(e) {
const item = e.target;
if (item.id === "logo" || item.classList.contains("burger")) {
mouse.classList.add("nav-active");
} else {
mouse.classList.remove("nav-active");
}
if (
item.classList.contains("explore") ||
item.classList.contains("form-submit")
) {
mouse.classList.add("explore-active");
gsap.to(".title-swipe", 1, { y: "0%" });
mouseTxt.innerText = "Tap!";
} else {
mouse.classList.remove("explore-active");
gsap.to(".title-swipe", 1, { y: "100%" });
mouseTxt.innerText = "";
}
if (
item.classList.contains("slide") ||
item.classList.contains("hero-desc")
) {
mouse.classList.add("color-active");
} else {
mouse.classList.remove("color-active");
}
}
function navToggle(e) {
if (!e.target.classList.contains("active")) {
e.target.classList.add("active");
gsap.to("#logo", 0.5, { display: "none" }, "-=1");
gsap.to(".line1", 0.5, { rotate: "45", y: 5, background: "black" });
gsap.to(".line2", 0.5, { rotate: "-45", y: -5, background: "black" });
gsap.to(".line3", 0.1, { display: "none" }, "-=1");
gsap.to(".nav-bar", 1, { clipPath: "circle(2500px at 0% -10%)" });
document.body.classList.add("hide");
} else {
e.target.classList.remove("active");
gsap.to("#logo", 0.5, { display: "block" }, "-=0.1");
gsap.to(".line1", 0.5, { rotate: "0", y: 0, background: "black" });
gsap.to(".line2", 0.5, { rotate: "0", y: 0, background: "black" });
gsap.to(".line3", 0.1, { display: "block" }, "-=1");
gsap.to(".nav-bar", 1, { clipPath: "circle(50px at 0% -10%)" });
document.body.classList.remove("hide");
}
}
let logo = document.querySelector("#logo");
//barba transitions
barba.init({
views: [
{
namespace: "home",
beforeEnter() {
animateSlides();
logo.href = "./index.html";
},
beforeLeave() {
slideScene.destroy();
pageScene.destroy();
controller.destroy();
},
},
{
namespace: "project",
beforeEnter() {
logo.href = "../index.html";
animateProjects();
gsap.fromTo(
".nav-header",
1,
{ y: "100%" },
{ y: "0%", ease: "power2.inOut" }
);
},
beforeLeave() {
controller.destroy();
projectScene.destroy();
},
},
{
namespace: "contact",
beforeEnter() {
logo.href = "../index.html";
animateContact();
},
},
],
transitions: [
{
leave({ current, next }) {
let done = this.async();
//adding animation
const tl = gsap.timeline({ defaults: { ease: "power2.inOut" } });
tl.fromTo(current.container, 1, { opacity: 1 }, { opacity: 0 });
tl.fromTo(
".swipe",
1,
{ x: "-100%" },
{ x: "0%", onComplete: done },
"-=0.5"
);
},
enter({ current, next }) {
let done = this.async();
//scrolling to top
window.scrollTo(0, 0);
//adding animation
const tl = gsap.timeline({ defaults: { ease: "power2.inOut" } });
tl.fromTo(
".swipe",
1,
{ y: "0%" },
{ y: "-100%", stagger: 0.2, onComplete: done }
);
tl.fromTo(next.container, 1, { opacity: 0 }, { opacity: 1 });
},
},
],
});
//function for animation of projects
function animateProjects() {
controller = new ScrollMagic.Controller();
const projects = document.querySelectorAll(".project-anim");
projects.forEach((project, index, projects) => {
let projectTl = gsap.timeline({
defaults: { duration: 1.5, ease: "power2.inOut" },
});
let nextSlide = projects.length - 1 === index ? "end" : projects[index + 1];
let nextImg = nextSlide.querySelector("img");
projectTl.fromTo(project, { opacity: 1 }, { opacity: 0 });
// projectTl.fromTo(nextSlide, { x: "-100%" }, { x: "0%" }, "-=0.1");
// projectTl.fromTo(
// nextImg,
// { scale: 2, x: "-70%" },
// { scale: 1, x: "0%" },
// "-=0.9"
// );
projectScene = new ScrollMagic.Scene({
triggerElement: project,
duration: "100%",
triggerHook: 0,
})
.setPin(project, { pushFollowers: false })
.setTween(projectTl)
// .addIndicators({
// colorStart: "white",
// colorTrigger: "white",
// name: "project",
// })
.addTo(controller);
});
}
function openPopup() {
if (!popup.classList.contains("active")) {
popup.classList.add("active");
let tl = gsap.timeline({
defaults: { duration: 0.5, ease: "power2.inOut" },
});
tl.fromTo(".popup", { y: "0%" }, { y: "-100%" });
document.body.classList.add("hide");
}
}
function closeSkillPopup() {
popup.classList.remove("active");
document.body.classList.remove("hide");
}
function animateContact() {
let revealForm = document.querySelector(".reveal-form");
let tl = gsap.timeline({
defaults: { duration: 3, ease: "power2.inOut" },
});
tl.fromTo(revealForm, { x: "0%" }, { x: "-100%" });
}
//event listeners
burger.addEventListener("click", navToggle);
window.addEventListener("mousemove", cursor);
window.addEventListener("mouseover", activeCursor);
skillsBtn.addEventListener("click", openPopup);
closePopup.addEventListener("click", closeSkillPopup);