-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportfolio-js.js
More file actions
57 lines (49 loc) · 1.42 KB
/
Copy pathportfolio-js.js
File metadata and controls
57 lines (49 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Typing effect
const typingText = document.getElementById('typing-text');
const words = ['Vivekananda'];
let wordIndex = 0;
let charIndex = 0;
let isDeleting = false;
function type() {
const word = words[wordIndex];
if (isDeleting) {
charIndex--;
} else {
charIndex++;
}
typingText.textContent = word.substring(0, charIndex);
if (!isDeleting && charIndex === word.length) {
isDeleting = true;
setTimeout(type, 1000);
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
wordIndex = (wordIndex + 1) % words.length;
setTimeout(type, 500);
} else {
setTimeout(type, isDeleting ? 100 : 150);
}
}
type();
// Contact form submission with alert and redirect
const contactForm = document.getElementById('contactForm');
if (contactForm) {
contactForm.addEventListener('submit', function (e) {
e.preventDefault(); // Stop default submit
const formData = new FormData(this);
// Submit using fetch to FormSubmit.co
fetch(this.action, {
method: this.method,
body: formData
}).then(response => {
if (response.ok) {
alert('Thanks for contacting me! I will reach out to you soon.');
this.reset();
window.location.href = 'thank-you.html'; // Redirect after success
} else {
alert('Something went wrong. Please try again!');
}
}).catch(() => {
alert('Something went wrong. Please try again!');
});
});
}