@@ -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
77102window . 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} ) ;
0 commit comments