66
77import { animate , stagger , createTimeline } from 'animejs' ;
88import { initCardAnimations , optimizeCardPerformance } from './card-animations.js' ;
9+ import { throttle , rafThrottle } from '../utils/throttle' ;
910
1011// Define global anime interface
1112interface AnimeGlobal {
@@ -15,7 +16,7 @@ interface AnimeGlobal {
1516}
1617
1718// Make animate available globally for compatibility
18- ( window as Window & { anime : AnimeGlobal } ) . anime = {
19+ ( window as any ) . anime = {
1920 animate,
2021 stagger,
2122 createTimeline
@@ -143,8 +144,8 @@ function animateMatrix(currentTime: number = 0): void {
143144// Start animation
144145requestAnimationFrame ( animateMatrix ) ;
145146
146- // Scroll event handler with parallax
147- window . addEventListener ( 'scroll' , ( ) => {
147+ // Throttled scroll handler for better performance
148+ const handleScroll = rafThrottle ( ( ) => {
148149 const scrollTop = window . pageYOffset || document . documentElement . scrollTop ;
149150
150151 // Parallax effect for Matrix canvas
@@ -161,6 +162,9 @@ window.addEventListener('scroll', () => {
161162 }
162163} ) ;
163164
165+ // Scroll event handler with RAF throttling
166+ window . addEventListener ( 'scroll' , handleScroll , { passive : true } ) ;
167+
164168// Mobile menu toggle handler
165169document . addEventListener ( 'DOMContentLoaded' , ( ) => {
166170 const menuToggle = document . querySelector ( '.menu-toggle' ) as HTMLElement | null ;
@@ -562,7 +566,7 @@ function initAnimeAnimations(): void {
562566 // Staggered fade-in for project cards
563567 const projectCards = document . querySelectorAll ( '.project-card' ) ;
564568 if ( projectCards . length > 0 ) {
565- animate ( projectCards , {
569+ animate ( projectCards as NodeListOf < HTMLElement > , {
566570 opacity : { from : 0 , to : 1 } ,
567571 translateY : { from : 30 , to : 0 } ,
568572 scale : { from : 0.95 , to : 1 } ,
@@ -576,7 +580,7 @@ function initAnimeAnimations(): void {
576580 const counters = document . querySelectorAll ( '.count' ) ;
577581 counters . forEach ( counter => {
578582 const target = parseInt ( counter . getAttribute ( 'data-target' ) || counter . textContent || '0' ) ;
579- animate ( counter , {
583+ animate ( counter as HTMLElement , {
580584 textContent : { from : 0 , to : target } ,
581585 round : 1 ,
582586 duration : 2000 ,
@@ -587,15 +591,15 @@ function initAnimeAnimations(): void {
587591 // Subtle button hover effect - removed particle animation
588592 document . querySelectorAll ( '.cta-button, .neo-matrix-btn, .matrix-btn' ) . forEach ( button => {
589593 button . addEventListener ( 'mouseenter' , ( ) => {
590- animate ( button , {
594+ animate ( button as HTMLElement , {
591595 scale : 1.05 ,
592596 duration : 200 ,
593597 ease : 'outQuad'
594598 } ) ;
595599 } ) ;
596600
597601 button . addEventListener ( 'mouseleave' , ( ) => {
598- animate ( button , {
602+ animate ( button as HTMLElement , {
599603 scale : 1 ,
600604 duration : 200 ,
601605 ease : 'outQuad'
@@ -606,7 +610,7 @@ function initAnimeAnimations(): void {
606610 // Simple fade-in for headers - more professional
607611 const headers = document . querySelectorAll ( 'h1, h2:not(.introduction-h2)' ) ;
608612 headers . forEach ( ( header ) => {
609- animate ( header , {
613+ animate ( header as HTMLElement , {
610614 opacity : { from : 0 , to : 1 } ,
611615 translateY : { from : 10 , to : 0 } ,
612616 duration : 600 ,
@@ -617,7 +621,7 @@ function initAnimeAnimations(): void {
617621 // Smooth scroll indicator animation
618622 const scrollIndicators = document . querySelectorAll ( '.scroll-down' ) ;
619623 if ( scrollIndicators . length > 0 ) {
620- animate ( scrollIndicators , {
624+ animate ( scrollIndicators as NodeListOf < HTMLElement > , {
621625 translateY : { from : 0 , to : 10 } ,
622626 opacity : { from : 1 , to : 0.7 } ,
623627 alternate : true ,
@@ -631,15 +635,15 @@ function initAnimeAnimations(): void {
631635 const galleryItems = document . querySelectorAll ( '.gallery-item, .introduction-img img' ) ;
632636 galleryItems . forEach ( item => {
633637 item . addEventListener ( 'mouseenter' , ( ) => {
634- animate ( item , {
638+ animate ( item as HTMLElement , {
635639 scale : 1.02 ,
636640 duration : 300 ,
637641 ease : 'outQuad'
638642 } ) ;
639643 } ) ;
640644
641645 item . addEventListener ( 'mouseleave' , ( ) => {
642- animate ( item , {
646+ animate ( item as HTMLElement , {
643647 scale : 1 ,
644648 duration : 300 ,
645649 ease : 'outQuad'
@@ -661,7 +665,7 @@ function initScrollReveal(): void {
661665
662666 // Animate section content
663667 const content = entry . target . querySelectorAll ( 'p, li, .card, .tech-item' ) ;
664- animate ( content , {
668+ animate ( content as NodeListOf < HTMLElement > , {
665669 opacity : { from : 0 , to : 1 } ,
666670 translateY : { from : 20 , to : 0 } ,
667671 delay : stagger ( 50 ) ,
0 commit comments