-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (43 loc) · 1.59 KB
/
Copy pathscript.js
File metadata and controls
51 lines (43 loc) · 1.59 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
// 1. Change Navbar background on scroll
const navbar = document.getElementById('navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.style.background = '#f4f4f4'; // Make navbar slightly gray on scroll
navbar.style.boxShadow = '0 4px 6px rgba(0,0,0,0.1)';
} else {
navbar.style.background = '#fff'; // Return to white at the top
navbar.style.boxShadow = '0 2px 5px rgba(0,0,0,0.1)';
}
});
// 2. Simple Typing Effect for the Hero Section
const textElement = document.querySelector('.typing-text');
const textArray = ["I am a Web Developer.", "I build amazing websites."];
let arrayIndex = 0;
let charIndex = 0;
let isDeleting = false;
function type() {
const currentText = textArray[arrayIndex];
if (isDeleting) {
textElement.textContent = currentText.substring(0, charIndex - 1);
charIndex--;
} else {
textElement.textContent = currentText.substring(0, charIndex + 1);
charIndex++;
}
let typeSpeed = isDeleting ? 50 : 100;
if (!isDeleting && charIndex === currentText.length) {
typeSpeed = 2000; // Pause at end of word
isDeleting = true;
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
arrayIndex = (arrayIndex + 1) % textArray.length;
typeSpeed = 500; // Pause before starting new word
}
setTimeout(type, typeSpeed);
}
// Start the typing effect when the document loads
document.addEventListener('DOMContentLoaded', () => {
// Clear the static text first
textElement.textContent = "";
type();
});