-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
168 lines (141 loc) · 5.93 KB
/
Copy pathscript.js
File metadata and controls
168 lines (141 loc) · 5.93 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
document.addEventListener('DOMContentLoaded', () => {
// main elements for language switching functionality
const flipButton = document.querySelector('#flip-button');
const mainTitle = document.querySelector('#main-title');
const subtitle = document.querySelector('#subtitle');
const footerText = document.querySelector('#footer-text');
const cvContent = document.querySelector('#cv-content');
// language configuration and state management
let isPolish = false;
const translations = {
en: {
button: 'Switch to Polish',
title: 'My Curriculum Vitae',
subtitle: 'Click the button below to switch between English and Polish versions',
footer: '© 2025 My CV | All rights reserved'
},
pl: {
button: 'Przełącz na angielski',
title: 'Moje Curriculum Vitae',
subtitle: 'Kliknij przycisk poniżej, aby przełączyć między wersją polską i angielską',
footer: '© 2025 Moje CV | Wszystkie prawa zastrzeżone'
}
};
// function to handle language updates and UI changes
function updateLanguage(lang) {
const text = translations[lang];
flipButton.textContent = text.button;
updateTitle(lang === 'en');
footerText.textContent = text.footer;
document.documentElement.lang = lang;
}
flipButton.addEventListener('click', () => {
isPolish = !isPolish;
updateLanguage(isPolish ? 'pl' : 'en');
cvContent.classList.toggle('flipped');
// note paper flipping
document.querySelector('.note-paper').classList.toggle('flipped');
});
// interaction logic
const lanyard = document.querySelector('.lanyard');
const lanyardString = document.querySelector('.lanyard-string');
const badge = document.querySelector('.badge');
const badgeContent = document.querySelector('.badge-content');
// physics simulation variables for smooth animation
let isDragging = false;
let startX, startY;
let currentX, currentY;
let velocity = { x: 0, y: 0 };
let rafId;
// function for smooth movement
function animate() {
if (!isDragging) {
velocity.x *= 0.95;
velocity.y *= 0.95;
currentX += velocity.x;
currentY += velocity.y;
const rotation = (currentX - startX) * 0.1;
const boundedRotation = Math.max(Math.min(rotation, 45), -45);
lanyard.style.transform = `rotate(${boundedRotation}deg)`;
if (Math.abs(velocity.x) > 0.01 || Math.abs(velocity.y) > 0.01) {
rafId = requestAnimationFrame(animate);
} else {
lanyard.style.animation = 'lanyardSway 3s ease-in-out infinite';
}
}
}
// mouse handler for dragging interaction
function handleMouseMove(e) {
if (!isDragging) return;
const dx = e.clientX - currentX;
const dy = e.clientY - currentY;
velocity.x = dx;
velocity.y = dy;
currentX = e.clientX;
currentY = e.clientY;
const rotation = (currentX - startX) * 0.1;
const boundedRotation = Math.max(Math.min(rotation, 45), -45);
lanyard.style.transform = `rotate(${boundedRotation}deg)`;
}
lanyardString.addEventListener('mousedown', (e) => {
isDragging = true;
startX = currentX = e.clientX;
startY = currentY = e.clientY;
lanyard.style.animation = 'none';
lanyard.style.transition = 'none';
document.addEventListener('mousemove', handleMouseMove);
});
document.addEventListener('mouseup', () => {
if (isDragging) {
isDragging = false;
document.removeEventListener('mousemove', handleMouseMove);
lanyard.style.transition = 'transform 0.5s ease';
lanyard.style.transform = 'rotate(0deg)';
setTimeout(() => {
lanyard.style.animation = 'lanyardSway 3s ease-in-out infinite';
}, 500);
}
});
// badge hover effect
badge.addEventListener('mousemove', (e) => {
if (!isDragging) {
const rect = badge.getBoundingClientRect();
const x = (e.clientX - rect.left - rect.width / 2) / rect.width;
const y = (e.clientY - rect.top - rect.height / 2) / rect.height;
badgeContent.style.transform = `perspective(1000px) rotateY(${x * 20}deg) rotateX(${-y * 20}deg)`;
}
});
badge.addEventListener('mouseleave', () => {
if (!isDragging) {
badgeContent.style.transform = 'none';
}
});
// initial animation
lanyard.style.animation = 'lanyardSway 3s ease-in-out infinite';
// accessibility
flipButton.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
flipButton.click();
}
});
});
// title update function with animation handling
function updateTitle(isEnglish) {
const title = document.getElementById('main-title');
const subtitle = document.getElementById('subtitle');
// restart animation
title.classList.remove('animate');
subtitle.classList.remove('animate');
//tTrigger reflow
void title.offsetWidth;
void subtitle.offsetWidth;
// add animation class
title.classList.add('animate');
subtitle.classList.add('animate');
// update content
title.textContent = isEnglish ? 'My Curriculum Vitae' : 'Moje CV';
subtitle.textContent = isEnglish ?
'Click the button below to switch between English and Polish versions' :
'Kliknij przycisk poniżej, aby przełączyć między wersjami angielską i polską';
}