-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
49 lines (41 loc) · 1.46 KB
/
scripts.js
File metadata and controls
49 lines (41 loc) · 1.46 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
// Typing animation
const words = ["Python, Scratch, Roblox, Java", "Build games, apps, and more!", "No experience needed!", "Start your coding journey today!"];
let wordIndex = 0;
let charIndex = 0;
let isDeleting = false;
const typingElement = document.getElementById('typingText');
function type() {
const currentWord = words[wordIndex];
if (isDeleting) {
typingElement.textContent = currentWord.substring(0, charIndex - 1);
charIndex--;
} else {
typingElement.textContent = currentWord.substring(0, charIndex + 1);
charIndex++;
}
if (!isDeleting && charIndex === currentWord.length) {
setTimeout(() => isDeleting = true, 2000);
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
wordIndex = (wordIndex + 1) % words.length;
}
const typingSpeed = isDeleting ? 50 : 100;
setTimeout(type, typingSpeed);
}
type();
// Smooth scrolling
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
});
});
// Hamburger menu
const hamburger = document.querySelector('.hamburger');
const navUl = document.querySelector('nav ul');
hamburger.addEventListener('click', () => {
navUl.classList.toggle('active');
});