-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
144 lines (121 loc) · 4.82 KB
/
app.js
File metadata and controls
144 lines (121 loc) · 4.82 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
const hamburger = document.getElementById('hamburger');
const menu = document.getElementById('menu');
const menuBackdrop = document.getElementById('menuBackdrop');
const navLinks = document.querySelectorAll('#menu a');
const line1 = document.getElementById('line1');
const line2 = document.getElementById('line2');
const line3 = document.getElementById('line3');
let isMenuOpen = false;
// Toggle menu with animation
hamburger.addEventListener('click', () => {
isMenuOpen = !isMenuOpen;
if (isMenuOpen) {
menu.classList.remove('hidden');
menuBackdrop.classList.remove('hidden');
// Animate hamburger to X
line1.style.transform = 'rotate(45deg) translateY(10px)';
line2.style.opacity = '0';
line3.style.transform = 'rotate(-45deg) translateY(-10px)';
} else {
menu.classList.add('hidden');
menuBackdrop.classList.add('hidden');
// Reset hamburger animation
line1.style.transform = 'rotate(0) translateY(0)';
line2.style.opacity = '1';
line3.style.transform = 'rotate(0) translateY(0)';
}
});
// Close menu when clicking backdrop
menuBackdrop.addEventListener('click', () => {
hamburger.click();
});
// Close mobile menu when a link is clicked
navLinks.forEach(link => {
link.addEventListener("click", () => {
if (isMenuOpen) {
hamburger.click();
}
});
});
// Close menu on window resize to desktop
window.addEventListener('resize', () => {
if (window.innerWidth >= 768 && isMenuOpen) {
hamburger.click();
}
});
// Toggle intro card functionality
const toggleSection = document.querySelector("#toggleSection");
const toggleButton = document.querySelector("#toggleButton");
const toggleFloatingButton = document.querySelector("#toggleFloatingButton");
function toggleIntroCard() {
if (!toggleSection || !toggleButton || !toggleFloatingButton) {
console.error("Toggle elements not found");
return;
}
// Toggle display using inline styles for reliable toggling
const cardIsVisible = toggleSection.style.display !== "none";
if (cardIsVisible) {
// Hide card, show button
toggleSection.style.display = "none";
toggleFloatingButton.style.display = "block";
toggleButton.textContent = "SHOW ME";
} else {
// Show card, hide button
toggleSection.style.display = "flex";
toggleFloatingButton.style.display = "none";
toggleButton.textContent = "HIDE ME";
}
}
// Ensure elements exist before adding listeners
if (toggleButton && toggleSection && toggleFloatingButton) {
// Make buttons clickable
toggleButton.style.cursor = "pointer";
toggleFloatingButton.style.cursor = "pointer";
toggleButton.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
toggleIntroCard();
});
toggleFloatingButton.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
toggleIntroCard();
});
console.log("Toggle functionality initialized successfully");
} else {
console.warn("Toggle functionality could not be initialized. Some elements are missing.");
if (!toggleButton) console.warn("toggleButton not found");
if (!toggleSection) console.warn("toggleSection not found");
if (!toggleFloatingButton) console.warn("toggleFloatingButton not found");
}
// Projects Carousel Scroll Functionality
const projectsContainer = document.getElementById('projectsContainer');
const scrollLeftBtn = document.getElementById('scrollLeft');
const scrollRightBtn = document.getElementById('scrollRight');
if (projectsContainer && scrollLeftBtn && scrollRightBtn) {
// Scroll amount in pixels
const scrollAmount = 320;
scrollLeftBtn.addEventListener('click', () => {
projectsContainer.scrollBy({
left: -scrollAmount,
behavior: 'smooth'
});
});
scrollRightBtn.addEventListener('click', () => {
projectsContainer.scrollBy({
left: scrollAmount,
behavior: 'smooth'
});
});
// Update button visibility based on scroll position
function updateScrollButtons() {
scrollLeftBtn.style.opacity = projectsContainer.scrollLeft > 0 ? '1' : '0.5';
scrollLeftBtn.style.pointerEvents = projectsContainer.scrollLeft > 0 ? 'auto' : 'none';
const maxScroll = projectsContainer.scrollWidth - projectsContainer.clientWidth;
scrollRightBtn.style.opacity = projectsContainer.scrollLeft < maxScroll ? '1' : '0.5';
scrollRightBtn.style.pointerEvents = projectsContainer.scrollLeft < maxScroll ? 'auto' : 'none';
}
projectsContainer.addEventListener('scroll', updateScrollButtons);
window.addEventListener('resize', updateScrollButtons);
updateScrollButtons();
}