-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
118 lines (99 loc) · 4.11 KB
/
script.js
File metadata and controls
118 lines (99 loc) · 4.11 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
document.addEventListener('DOMContentLoaded', () => {
// --- Navigation Menu Toggle (Mobile) ---
const hamburger = document.querySelector('.hamburger');
const navLinks = document.querySelector('.nav-links');
const navLinksItems = document.querySelectorAll('.nav-links li a');
hamburger.addEventListener('click', () => {
navLinks.classList.toggle('active');
hamburger.classList.toggle('active'); // You can add CSS animation for hamburger here if desired
});
// Close mobile menu when a link is clicked
navLinksItems.forEach(item => {
item.addEventListener('click', () => {
navLinks.classList.remove('active');
hamburger.classList.remove('active');
});
});
// --- Typing Effect ---
const typingText = document.querySelector('.typing-text');
const words = ["Lyricist", "Content Writer", "Creative Thinker", "Film Critic"];
let wordIndex = 0;
let charIndex = 0;
let isDeleting = false;
let typeSpeed = 100;
function type() {
const currentWord = words[wordIndex];
if (isDeleting) {
typingText.textContent = currentWord.substring(0, charIndex - 1);
charIndex--;
typeSpeed = 50; // Faster when deleting
} else {
typingText.textContent = currentWord.substring(0, charIndex + 1);
charIndex++;
typeSpeed = 100; // Normal typing speed
}
if (!isDeleting && charIndex === currentWord.length) {
// Word complete, pause before deleting
isDeleting = true;
typeSpeed = 2000;
} else if (isDeleting && charIndex === 0) {
// Deletion complete, switch to next word
isDeleting = false;
wordIndex = (wordIndex + 1) % words.length;
typeSpeed = 500;
}
setTimeout(type, typeSpeed);
}
// Start typing effect
if(typingText) {
type();
}
// --- Smooth Scrolling for Anchor Links ---
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
// Account for fixed header height
const headerOffset = 80;
const elementPosition = targetElement.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: "smooth"
});
}
});
});
// --- Scroll Animations (Intersection Observer) ---
const observerOptions = {
threshold: 0.1
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate');
}
});
}, observerOptions);
const elementsToAnimate = document.querySelectorAll('.section-title, .about-text, .skill-card, .timeline-item, .portfolio-card, .contact-box');
elementsToAnimate.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.6s ease-out, transform 0.6s ease-out';
observer.observe(el);
});
// Add 'animate' class behavior dynamically via JS style injection or rely on CSS class if present
// Let's rely on standard CSS transition we just set inline, but adding a class allows for cleaner CSS management if moved there.
// Ideally, we move the transition styles to CSS. For now, let's just make the .animate class toggle opacity/transform.
const styleSheet = document.createElement("style");
styleSheet.textContent = `
.animate {
opacity: 1 !important;
transform: translateY(0) !important;
}
`;
document.head.appendChild(styleSheet);
});