-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
144 lines (130 loc) · 4.13 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
function init() {
const slides = document.querySelectorAll(".slide");
const pages = document.querySelectorAll(".page");
const backgrounds = [
`radial-gradient(#2b3760, #0b1023)`,
`radial-gradient(#4e3022, #161616)`,
`radial-gradient(#4e4342, #161616)`,
];
// Tracker
let current = 0;
let scrollSlide = 0;
slides.forEach((slide, index) => {
slide.addEventListener("click", function () {
changeDots(this);
nextSlide(index);
scrollSlide = index;
});
});
function changeDots(dot) {
slides.forEach((slide) => {
slide.classList.remove("active");
});
dot.classList.add("active");
}
function nextSlide(pageNumber) {
const nextPage = pages[pageNumber];
const currentPage = pages[current];
const nextLeft = nextPage.querySelector(".hero .model-left");
const nextRight = nextPage.querySelector(".hero .model-right");
const currentLeft = currentPage.querySelector(".hero .model-left");
const currentRight = currentPage.querySelector(".hero .model-right");
const nextText = nextPage.querySelector(".details");
const portofolio = document.querySelectorAll(".portofolio");
// Animations Using GSAP
const tl = new TimelineMax({
onStart: function () {
slides.forEach((slide) => {
slide.styles.pointerEvents = "none";
});
},
onComplete: function () {
slides.forEach((slide) => {
slide.styles.pointerEvents = "none";
});
},
});
tl.fromTo(currentLeft, 0.3, { y: "-10%" }, { y: "-100%" })
.fromTo(currentRight, 0.3, { y: "-10%" }, { y: "-100%" }, "-=0.2")
.to(portofolio, 0.3, { backgroundImage: backgrounds[pageNumber] })
.fromTo(
currentPage,
0.3,
{ opacity: 1, pointerEvents: "all" },
{ opacity: 0, pointerEvents: "none" }
)
.fromTo(
nextPage,
0.3,
{ opacity: 0, pointerEvents: "none" },
{ opacity: 1, pointerEvents: "all" },
"-=0.6"
)
.fromTo(nextLeft, 0.3, { y: "-100%" }, { y: "-10%" }, "-=0.6")
.fromTo(nextRight, 0.3, { y: "-100%" }, { y: "10%" }, "-=0.8")
.fromTo(nextText, 0.3, { opacity: 0, y: 30 }, { opacity: 1, y: 0 })
.set(nextLeft, { clearProps: "all" })
.set(nextRight, { clearProps: "all" });
current = pageNumber;
}
// Scroll
document.addEventListener("wheel", throttle(scrollChange, 1500));
document.addEventListener("touchmove", throttle(scrollChange, 1500));
function switchDots(dotNumber) {
const activeDot = document.querySelectorAll(".slide")[dotNumber];
slides.forEach((slide) => {
slide.classList.remove("active");
});
activeDot.classList.add("active");
}
function scrollChange(e) {
if (e.deltaY > 0) {
scrollSlide += 1;
} else {
scrollSlide -= 1;
}
if (scrollSlide > 2) {
scrollSlide = 0;
}
if (scrollSlide < 0) {
scrollSlide = 2;
}
switchDots(scrollSlide);
nextSlide(scrollSlide);
console.log(scrollSlide);
}
const hamburger = document.querySelector(".menu");
const hamburgerLines = document.querySelectorAll(".menu line");
const navOpen = document.querySelector(".nav-open");
const contact = document.querySelector(".contact");
const social = document.querySelector(".social");
const logo = document.querySelector(".logo");
const tl = new TimelineMax({ paused: true, reversed: true });
tl.to(navOpen, 0.5, { y: 0 })
.fromTo(contact, 0.5, { opacity: 0, y: 10 }, { opacity: 1, y: 0 }, "-=0.1")
.fromTo(social, 0.5, { opacity: 0, y: 10 }, { opacity: 1, y: 0 }, "-=0.5")
.fromTo(logo, 0.2, { color: "white" }, { color: "black" }, "-=1")
.fromTo(
hamburgerLines,
0.2,
{ stroke: "white" },
{ stroke: "black" },
"-=1"
);
hamburger.addEventListener("click", () => {
tl.reversed() ? tl.play() : tl.reverse();
});
}
function throttle(func, limit) {
let inThrottle;
return function () {
const args = arguments;
const context = this;
if (!inThrottle) {
func.apply(context, args);
inThrottle = true;
setTimeout(() => (inThrottle = false), limit);
}
};
}
init();