-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (63 loc) · 2.56 KB
/
Copy pathscript.js
File metadata and controls
76 lines (63 loc) · 2.56 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// --- 1. Animated Typing Effect ---
const typingTextElement = document.getElementById('typing-text');
const phrases = ["DevOps Enthusiast", "Linux Administrator", "Cloud Engineer"];
let phraseIndex = 0;
let letterIndex = 0;
let isDeleting = false;
function typeEffect() {
const currentPhrase = phrases[phraseIndex];
if (isDeleting) {
// Remove a letter
typingTextElement.textContent = currentPhrase.substring(0, letterIndex - 1);
letterIndex--;
} else {
// Add a letter
typingTextElement.textContent = currentPhrase.substring(0, letterIndex + 1);
letterIndex++;
}
// Determine typing speed
let typingSpeed = isDeleting ? 50 : 100;
// Logic for pausing at the end of a phrase and before deleting
if (!isDeleting && letterIndex === currentPhrase.length) {
typingSpeed = 2000; // Pause at end of word
isDeleting = true;
} else if (isDeleting && letterIndex === 0) {
isDeleting = false;
phraseIndex = (phraseIndex + 1) % phrases.length;
typingSpeed = 500; // Pause before typing next word
}
setTimeout(typeEffect, typingSpeed);
}
// Start typing effect on load
document.addEventListener("DOMContentLoaded", () => {
if(typingTextElement) typeEffect();
});
// --- 2. Scroll Animations & Skill Progress Bars ---
const fadeElements = document.querySelectorAll('.fade-in');
const skillBars = document.querySelectorAll('.skill-per');
const observerOptions = {
root: null,
rootMargin: '0px',
threshold: 0.2 // Trigger when 20% of the element is visible
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
// Add visible class to trigger fade-in CSS
entry.target.classList.add('visible');
// If it's the skills section, animate the progress bars
if (entry.target.classList.contains('skills-container')) {
skillBars.forEach(bar => {
const width = bar.style.width; // get the inline style width
bar.style.width = '0%'; // reset to 0
setTimeout(() => {
bar.style.width = width; // animate to target width
}, 200);
});
}
observer.unobserve(entry.target); // Stop observing once animated
}
});
}, observerOptions);
// Observe all fade-in elements
fadeElements.forEach(el => observer.observe(el));