-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (46 loc) · 1.58 KB
/
script.js
File metadata and controls
51 lines (46 loc) · 1.58 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
// Smooth scrolling
document.querySelectorAll('nav a').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const section = document.querySelector(this.getAttribute('href'));
section.scrollIntoView({ behavior: 'smooth' });
});
});
// Fade-in animation on scroll
const sections = document.querySelectorAll('section');
window.addEventListener('scroll', () => {
sections.forEach(section => {
const sectionTop = section.getBoundingClientRect().top;
const windowHeight = window.innerHeight;
if (sectionTop < windowHeight - 150) {
section.classList.add('visible');
}
});
});
// Add visible class initially to home
document.getElementById('home').classList.add('visible');
// Typing Animation
const typingText = document.getElementById('typing-text');
const phrases = ['Web Developer', 'Code Enthusiast', 'Creative Thinker'];
let phraseIndex = 0;
let charIndex = 0;
function type() {
if (charIndex < phrases[phraseIndex].length) {
typingText.textContent += phrases[phraseIndex].charAt(charIndex);
charIndex++;
setTimeout(type, 100);
} else {
setTimeout(erase, 2000);
}
}
function erase() {
if (charIndex > 0) {
typingText.textContent = phrases[phraseIndex].substring(0, charIndex - 1);
charIndex--;
setTimeout(erase, 50);
} else {
phraseIndex = (phraseIndex + 1) % phrases.length;
setTimeout(type, 500);
}
}
document.addEventListener('DOMContentLoaded', type);