Skip to content

Commit 60cc8e7

Browse files
committed
feat: Changed ducky animation to use GSAP
1 parent d776b79 commit 60cc8e7

3 files changed

Lines changed: 40 additions & 19 deletions

File tree

public/frosh/2025/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ <h1>Ducky Frosh 2025</h1>
3838
</nav>
3939
</div>
4040

41-
<div class="animated-duck-container">
41+
<div id="animated-duck-container">
4242
<svg
4343
viewBox="394.13419 484.70737 250 180"
4444
height="180"

public/frosh/2025/main.js

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const styleVars = window.getComputedStyle(document.body);
33
/**
44
* Animates the reeds parting when scrolling down.
55
*/
6-
function reedsParting() {
6+
function animateReedsParting() {
77
const scrollTrigger = {
88
trigger: '.hero',
99
start: 'top top',
@@ -23,6 +23,28 @@ function reedsParting() {
2323
});
2424
}
2525

26+
/**
27+
* Animates the duck swimming left to right.
28+
*/
29+
function animateDucky() {
30+
const duck = document.getElementById('animated-duck-container');
31+
32+
const start = -duck.getBoundingClientRect().width;
33+
const end = window.innerWidth;
34+
35+
const distance = end - start;
36+
const duration = distance / 100; // measured in pixels
37+
38+
gsap.set(duck, { left: start });
39+
gsap.to('#animated-duck-container', {
40+
left: end,
41+
repeat: -1, // infinitely loop
42+
ease: 'none',
43+
repeatDelay: 4,
44+
duration
45+
});
46+
}
47+
2648
/**
2749
* Makes the photos pop in from below.
2850
*/
@@ -44,7 +66,11 @@ function imagePopIn() {
4466
});
4567
}
4668

47-
function headerGradient() {
69+
/**
70+
* Animation that changes the text color of the header items when
71+
* scrolling down enough.
72+
*/
73+
function handleHeaderChanges() {
4874
gsap.to('header', {
4975
scrollTrigger: {
5076
trigger: 'main',
@@ -58,8 +84,7 @@ function headerGradient() {
5884
const navTrigger = {
5985
trigger: 'main',
6086
start: 'center center',
61-
toggleActions: 'play none play reverse',
62-
markers: true
87+
toggleActions: 'play none play reverse'
6388
};
6489

6590
gsap.to('header', {
@@ -76,9 +101,14 @@ function headerGradient() {
76101

77102
window.addEventListener('load', _ => {
78103
gsap.registerPlugin(ScrollTrigger, ScrollSmoother);
79-
reedsParting();
80-
headerGradient();
104+
animateReedsParting();
105+
handleHeaderChanges();
106+
animateDucky();
81107
if (window.matchMedia('(min-width: 1280px').matches) {
82108
imagePopIn();
83109
}
110+
window.addEventListener('resize', () => {
111+
gsap.killTweensOf('#animated-duck-container');
112+
animateDucky();
113+
});
84114
});

public/frosh/2025/style.css

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,27 +167,18 @@ header {
167167
}
168168
}
169169

170-
@keyframes duck-move {
171-
0% {
172-
left: -120%;
173-
}
174-
175-
100% {
176-
left: 120%;
177-
}
178-
}
179-
180170
.top-screen {
181171
position: relative;
182172
width: 100%;
183173
height: 100vh;
184174
overflow: hidden;
185175
z-index: 10;
186176

187-
&>.animated-duck-container {
177+
&>#animated-duck-container {
188178
position: absolute;
189179
bottom: -1vh;
190-
animation: duck-move 15s linear infinite;
180+
left: -120vw;
181+
/* Keeping this in case the animation break */
191182

192183
&>svg {
193184
height: 30vh;

0 commit comments

Comments
 (0)