11import elements from './elements.js' ;
22
33const { welcome } = elements . sections ;
4- const { pfp, pfpBg } = elements ;
4+ const { pfp, pfpBg, txt } = elements ;
55
6- const animationDelay = 1000 ;
6+ // txt
7+
8+ const strings = [ '<code/>' , '() => code;' , 'SELECT * FROM code;' ] ;
9+
10+ const stringDelay = 100 ;
11+ let displayCursor = false ;
12+ let index = 0 ;
13+
14+ export async function playTxtAnimation ( ) {
15+ await delay ( 5000 ) ;
16+ eraseString ( ) ;
17+ }
18+
19+ function showCursor ( ) {
20+ setInterval ( ( ) => {
21+ txt . classList . toggle ( 'cursor' ) ;
22+ } , 700 ) ;
23+ }
24+
25+ async function eraseString ( ) {
26+ if ( ! displayCursor ) {
27+ showCursor ( ) ;
28+ displayCursor = true ;
29+ }
30+ await delay ( 3000 ) ;
31+ let id = setInterval ( ( ) => {
32+ txt . textContent = txt . textContent . slice ( 0 , - 1 ) ;
33+ if ( txt . textContent . length === 0 ) {
34+ clearInterval ( id ) ;
35+ id = null ;
36+ index = ( index + 1 ) % strings . length ;
37+ writeString ( ) ;
38+ }
39+ } , stringDelay ) ;
40+ }
41+
42+ async function writeString ( ) {
43+ await delay ( 1000 ) ;
44+ const s = strings [ index ] ;
45+ let i = 0 ;
46+ let id = setInterval ( async ( ) => {
47+ txt . textContent = s . slice ( 0 , i ) ;
48+ i += 1 ;
49+ if ( i > s . length ) {
50+ clearInterval ( id ) ;
51+ id = null ;
52+ eraseString ( ) ;
53+ }
54+ } , stringDelay )
55+ }
756
857// Background
958
@@ -22,12 +71,13 @@ const transform = [
2271 'translateY(-5%) scale(0.875, 1.1)' ,
2372 'translateY(0%) scale(1)' ,
2473] ;
74+
2575const filter = [
2676 'brightness(0.25) drop-shadow(0 -0.25rem 0.5rem black) blur(2px)' ,
27- 'brightness(1.0) drop-shadow(0 0.5rem 0.5rem black) blur(0)' ,
77+ 'brightness(1.0) drop-shadow(0 0.5rem 0.75rem black) blur(0)' ,
2878] ;
2979
30- const pfpKeyframes = [
80+ const pfpIntroKeyframes = [
3181 {
3282 marginBottom : '15%' ,
3383 transform : transform [ 0 ] ,
@@ -62,18 +112,48 @@ const pfpKeyframes = [
62112 offset : 1 ,
63113 } ,
64114] ;
65- const pfpOptions = {
115+
116+ const pfpIntroOptions = {
66117 duration : 2000 ,
67118 easing : 'ease-in-out' ,
68119} ;
69120
70- export async function playAnimation ( ) {
71- await new Promise ( ( res ) => setTimeout ( ( ) => res ( ) , animationDelay ) ) ;
121+ const pfpKeyframes = [
122+ {
123+ transform : 'scale(1)' ,
124+ marginBottom : '7.5%' ,
125+ offset : 0 ,
126+ } ,
127+ {
128+ transform : 'scale(0.975, 1.025)' ,
129+ marginBottom : '7.5%' ,
130+ offset : 0.325 ,
131+ } ,
132+ {
133+ transform : 'scale(1)' ,
134+ marginBottom : '7.5%' ,
135+ offset : 1 ,
136+ } ,
137+ ] ;
138+
139+ const pfpOptions = {
140+ duration : 4000 ,
141+ easing : 'ease-in-out' ,
142+ iterations : Infinity ,
143+ } ;
144+
145+ const animationDelay = 1000 ;
146+
147+ export async function playPfpAnimation ( ) {
148+ await delay ( ) ;
72149 welcome . classList . remove ( 'loading' ) ;
73150
74151 pfp . style . transformOrigin = 'bottom center' ;
75152 animateTo ( pfpBg , bgKeyframes , bgOptions ) ;
76- animateTo ( pfp , pfpKeyframes , pfpOptions ) ;
153+ const intro = animateTo ( pfp , pfpIntroKeyframes , pfpIntroOptions ) ;
154+ intro . onfinish = ( ) => {
155+ animateTo ( pfp , pfpKeyframes , pfpOptions ) ;
156+ } ;
77157}
78158
79159function animateTo ( elt , keyframes , options ) {
@@ -87,3 +167,9 @@ function animateTo(elt, keyframes, options) {
87167 } ) ;
88168 return animation ;
89169}
170+
171+ function delay ( ms = 1000 ) {
172+ return new Promise ( ( res ) => {
173+ setTimeout ( res , ms ) ;
174+ } ) ;
175+ }
0 commit comments