@@ -33,19 +33,44 @@ document.addEventListener("DOMContentLoaded", () => {
3333 // Efek ketik otomatis di header
3434 const typingText = document . querySelector ( "header p" ) ;
3535 const words = [ "Mahasiswa Teknik Informatika" , "Web Developer" , "Tech Enthusiast" ] ;
36-
36+
3737 let wordIndex = 0 ;
3838 let charIndex = 0 ;
39-
39+ let isDeleting = false ;
40+
41+ // Ubah kecepatan di sini
42+ const typingSpeed = 150 ; // Kecepatan mengetik (ms)
43+ const erasingSpeed = 50 ; // Kecepatan menghapus (ms)
44+ const delayBetweenWords = 1500 ; // Jeda sebelum hapus teks (ms)
45+
4046 const typeEffect = ( ) => {
41- if ( charIndex < words [ wordIndex ] . length ) {
42- typingText . textContent += words [ wordIndex ] . charAt ( charIndex ) ;
47+ const currentWord = words [ wordIndex ] ;
48+
49+ if ( ! isDeleting ) {
50+ typingText . textContent = currentWord . substring ( 0 , charIndex + 1 ) ;
4351 charIndex ++ ;
44- setTimeout ( typeEffect , 100 ) ;
52+
53+ if ( charIndex === currentWord . length ) {
54+ isDeleting = true ;
55+ setTimeout ( typeEffect , delayBetweenWords ) ; // Tunggu sebelum mulai menghapus
56+ return ;
57+ }
4558 } else {
46- setTimeout ( ( ) => eraseEffect ( ) , 1500 ) ;
59+ typingText . textContent = currentWord . substring ( 0 , charIndex - 1 ) ;
60+ charIndex -- ;
61+
62+ if ( charIndex === 0 ) {
63+ isDeleting = false ;
64+ wordIndex = ( wordIndex + 1 ) % words . length ; // Pindah ke kata berikutnya
65+ }
4766 }
67+
68+ setTimeout ( typeEffect , isDeleting ? erasingSpeed : typingSpeed ) ;
4869 } ;
70+
71+ typeEffect ( ) ;
72+
73+
4974
5075 const eraseEffect = ( ) => {
5176 if ( charIndex > 0 ) {
0 commit comments