@@ -20,25 +20,37 @@ function pulse(state) {
2020 const img = document . querySelector ( '.logo-img' ) ;
2121 if ( ! img ) return ;
2222
23+ let startTime ;
24+ const duration = 1000 ; // full pulse cycle in ms (0.8 → 1 → 0.8)
25+
2326 if ( state === 'reset' ) {
24- clearInterval ( pulseInterval ) ;
25- pulseInterval = null ;
27+ cancelAnimationFrame ( pulseState ) ;
28+ pulseState = null ;
2629 img . style . transition = 'transform 0.2s ease' ;
2730 img . style . transform = 'scale(0.8)' ;
28- } else if ( state === true ) {
29- if ( pulseInterval ) return ; // already pulsing
30- let growing = true ;
31- img . style . transition = 'transform 0.2s ease' ;
32- pulseInterval = setInterval ( ( ) => {
33- img . style . transform = growing ? 'scale(1)' : 'scale(0.8)' ;
34- growing = ! growing ;
35- } , 200 ) ;
36- } else if ( state === false ) {
37- if ( pulseInterval ) {
38- clearInterval ( pulseInterval ) ;
39- pulseInterval = null ;
40- }
31+ return ;
32+ }
33+
34+ if ( state === false ) {
35+ cancelAnimationFrame ( pulseState ) ;
36+ pulseState = null ;
4137 img . style . transition = 'transform 0.2s ease' ;
4238 img . style . transform = 'scale(1)' ;
39+ return ;
4340 }
41+
42+ // state === true → start smooth pulsing
43+ cancelAnimationFrame ( pulseState ) ;
44+ startTime = null ;
45+
46+ function animate ( time ) {
47+ if ( ! startTime ) startTime = time ;
48+ const elapsed = time - startTime ;
49+ // sinusoidal smooth scaling: 0.8 → 1 → 0.8
50+ const scale = 0.9 + 0.1 * Math . sin ( ( elapsed / duration ) * 2 * Math . PI ) ;
51+ img . style . transform = `scale(${ scale } )` ;
52+ pulseState = requestAnimationFrame ( animate ) ;
53+ }
54+
55+ pulseState = requestAnimationFrame ( animate ) ;
4456}
0 commit comments