Skip to content

Commit 39a1369

Browse files
committed
memperbaiki js
1 parent 612b109 commit 39a1369

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<body>
3131
<header>
3232
<h1 class="fade-in">Muhammad Malik Nur</h1>
33-
<p class="fade-in">Mahasiswa D4 Teknik Informatika | Web Developer | Tech Enthusiast</p>
33+
<p class="fade-in">D4 Teknik Informatika | Web Developer | Tech Enthusiast</p>
3434
</header>
3535
<nav>
3636
<ul>

script.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)