-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
132 lines (120 loc) · 4.26 KB
/
script.js
File metadata and controls
132 lines (120 loc) · 4.26 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* ====================
THEME TOGGLE (animated)
==================== */
const body = document.body;
const themeToggle = document.getElementById('themeToggle');
const themeIcon = document.getElementById('themeIcon');
function setIconForTheme() {
if (body.classList.contains('theme-dark')) {
themeIcon.innerHTML = '<path d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>';
} else {
themeIcon.innerHTML = '<circle cx="12" cy="12" r="4" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/><path d="M12 2v2M12 20v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M2 12h2M20 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>';
}
}
setIconForTheme();
themeToggle.addEventListener('click', () => {
if (body.classList.contains('theme-light')) {
body.classList.remove('theme-light');
body.classList.add('theme-dark');
// small fade for accent transitions
} else {
body.classList.remove('theme-dark');
body.classList.add('theme-light');
}
setIconForTheme();
});
/* ====================
TYPEWRITER (roles)
==================== */
const typeEl = document.getElementById('typewriter');
const roles = ['BTech CSE Student!', 'Java Enthusiast!', 'Open Source Contributor!', 'Problem Solver!'];
let typeIndex = 0, charIndex = 0, deleting = false;
function typeLoop(){
const current = roles[typeIndex % roles.length];
if (!deleting) {
typeEl.textContent = current.slice(0, charIndex + 1);
charIndex++;
if (charIndex === current.length) {
deleting = true;
setTimeout(typeLoop, 1000);
return;
}
} else {
typeEl.textContent = current.slice(0, charIndex - 1);
charIndex--;
if (charIndex === 0) {
deleting = false;
typeIndex++;
}
}
setTimeout(typeLoop, deleting ? 80 : 120);
}
typeLoop();
/* ====================
SCROLL REVEAL & SKILL ANIMATION
==================== */
const revealEls = document.querySelectorAll('.reveal');
const fills = document.querySelectorAll('.fill');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
// animate skill bars if present within this section
entry.target.querySelectorAll('.fill').forEach(f => {
const value = f.dataset.fill || 60;
f.style.width = value + '%';
});
}
});
}, {threshold: 0.18});
revealEls.forEach(el => observer.observe(el));
/* ====================
PROJECT CARD 3D TILT (mouse)
==================== */
const projects = document.querySelectorAll('.project-card');
projects.forEach(card => {
const inner = card.querySelector('.card-inner');
card.addEventListener('mousemove', (e) => {
const rect = card.getBoundingClientRect();
const x = (e.clientX - rect.left) / rect.width;
const y = (e.clientY - rect.top) / rect.height;
const rotateY = (x - 0.5) * 14; // -7..7
const rotateX = (0.5 - y) * 8; // -4..4
inner.style.transform = `translateY(-6px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`;
});
card.addEventListener('mouseleave', () => {
inner.style.transform = '';
});
});
/* ====================
CONTACT FORM (demo feedback)
==================== */
const form = document.getElementById('contactForm');
form.addEventListener('submit', (e) => {
e.preventDefault();
const btn = form.querySelector('.cta-btn');
btn.textContent = 'Sending…';
btn.disabled = true;
// simulate send
setTimeout(() => {
btn.textContent = 'Sent ✓';
btn.style.transform = 'translateY(-2px)';
setTimeout(() => {
btn.textContent = 'Send Message';
btn.disabled = false;
form.reset();
}, 1400);
}, 900);
});
/* ====================
small accessibility tweaks
==================== */
document.querySelectorAll('a[href^="#"]').forEach(a => {
a.addEventListener('click', (e) => {
const target = document.querySelector(a.getAttribute('href'));
if (target) {
e.preventDefault();
target.scrollIntoView({behavior:'smooth', block:'start'});
}
});
});