forked from HackVerse/2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
236 lines (207 loc) · 4.91 KB
/
main.js
File metadata and controls
236 lines (207 loc) · 4.91 KB
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
AOS.init({ duration: 600, anchorPlacement: "center-bottom" });
const navLinks = document.querySelectorAll(".nav-item");
const menuToggle = document.getElementById("navbarNav");
const bsCollapse = new bootstrap.Collapse(menuToggle, { toggle: false });
navLinks.forEach((l) => {
l.addEventListener("click", () => {
bsCollapse.toggle();
});
});
$(window).scroll(testScroll);
var viewed = false;
function isScrolledIntoView(elem) {
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top;
var elemBottom = elemTop + $(elem).height();
return elemBottom <= docViewBottom && elemTop >= docViewTop;
}
function testScroll() {
if (isScrolledIntoView($(".milestone-number")) && !viewed) {
viewed = true;
$(".number-holder").each(function () {
$(this)
.prop("Counter", 0)
.animate(
{
Counter: $(this).text(),
},
{
duration: 4000,
easing: "swing",
step: function (now) {
$(this).text(Math.ceil(now));
},
}
);
});
}
}
gsap.registerPlugin(ScrollTrigger, MotionPathPlugin);
let speed = 200;
let scene1 = gsap.timeline();
ScrollTrigger.create({
animation: scene1,
trigger: "#hero",
start: "top top",
end: "80% center",
scrub: 3,
pin: true,
});
scene1.to("#skateperson", { x: -160, y: 50 });
gsap.to("#h2-1", {
yPercent: 10,
ease: "none",
scrollTrigger: {
trigger: ".scrollElement",
scrub: 2,
},
});
gsap.to("#skateperson", {
yPercent: 10,
ease: "none",
scrollTrigger: {
trigger: ".scrollElement",
scrub: 2,
},
});
gsap.to("#h2-2", {
yPercent: 50,
ease: "none",
scrollTrigger: {
trigger: ".scrollElement",
scrub: 1,
},
});
gsap.to("#h2-3", {
yPercent: 60,
ease: "none",
scrollTrigger: {
trigger: ".scrollElement",
scrub: 1,
},
});
gsap.to("#h2-4", {
yPercent: 80,
ease: "none",
scrollTrigger: {
trigger: ".scrollElement",
scrub: 1,
},
});
gsap.to("#h2-5", {
yPercent: 100,
ease: "none",
scrollTrigger: {
trigger: ".scrollElement",
scrub: 1,
},
});
gsap.to("#h2-6", {
yPercent: 100,
ease: "none",
scrollTrigger: {
trigger: ".scrollElement",
scrub: 1,
},
});
ScrollTrigger.create({
animation: scene1,
trigger: "#about-div",
start: "top top",
end: "80% center",
scrub: 3,
pin: true,
});
gsap.to("#a2-1", {
yPercent: 10,
ease: "none",
scrollTrigger: {
trigger: ".scrollElement",
scrub: 1,
},
});
gsap.to("#a2-2", {
yPercent: 10,
ease: "none",
scrollTrigger: {
trigger: ".scrollElement",
scrub: 1,
},
});
gsap
.timeline({
scrollTrigger: {
trigger: ".cloud-cover",
start: "-=250px bottom",
end: "top center",
scrub: 1,
},
})
.fromTo(".cloud1", { y: -200 }, { y: -550 }, 0)
.fromTo(".cloud2", { y: -150 }, { y: -250 }, 0)
.fromTo(".cloud3", { y: -50 }, { y: -400 }, 0);
// ScrollTrigger.create({
// animation: scene1,
// trigger: "#schedule-div",
// start: "top top",
// end: "80% center",
// scrub: 3,
// pin: true,
// });
// scene1.to("#iceberg-1", { x: -160, y: 50 });
// gsap.to("#iceberg-1", {
// yPercent: 10,
// ease: "none",
// scrollTrigger: {
// trigger: ".scrollElement",
// scrub: 2,
// },
// });
//reset scrollbar position after refresh
window.onbeforeunload = function () {
window.scrollTo(0, 0);
};
// Text animation
document.addEventListener("DOMContentLoaded", function (event) {
// array with texts to type in typewriter
var dataText = ["Imagine.", "Believe.", "Achieve!"];
// type one text in the typwriter
// keeps calling itself until the text is finished
function typeWriter(text, i, fnCallback) {
// chekc if text isn't finished yet
if (i < text.length) {
// add next character to h1
document.querySelector("h1").innerHTML =
text.substring(0, i + 1) +
'<span aria-hidden="true" id="typing-text"></span>';
// wait for a while and call this function again for next character
setTimeout(function () {
typeWriter(text, i + 1, fnCallback);
}, 100);
}
// text finished, call callback if there is a callback function
else if (typeof fnCallback == "function") {
// call callback after timeout
setTimeout(fnCallback, 700);
}
}
// start a typewriter animation for a text in the dataText array
function StartTextAnimation(i) {
if (typeof dataText[i] == "undefined") {
setTimeout(function () {
StartTextAnimation(0);
}, 20000);
}
// check if dataText[i] exists
if (i < dataText[i].length) {
// text exists! start typewriter animation
typeWriter(dataText[i], 0, function () {
// after callback (and whole text has been animated), start next text
StartTextAnimation(i + 1);
});
}
}
// start the text animation
StartTextAnimation(0);
});