-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (44 loc) · 1.84 KB
/
script.js
File metadata and controls
51 lines (44 loc) · 1.84 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
/**
* This script contains functionality specific to the index.html page.
* It handles:
* 1. The staggered animation for the link items on load.
* 2. The expand/collapse functionality for the showcase items.
*/
document.addEventListener('DOMContentLoaded', () => {
// 1. Animate link items on load
const links = document.querySelectorAll('.link-item');
if (links.length > 0) {
links.forEach((link, index) => {
const delay = index * 75 + 200;
link.style.transition = `opacity 0.4s ease-out ${delay}ms, transform 0.4s ease-out ${delay}ms`;
requestAnimationFrame(() => {
link.style.opacity = '1';
link.style.transform = 'translateY(0)';
});
});
}
// 2. Handle showcase item expansion
const showcaseContainer = document.querySelector('.showcase-container');
if (showcaseContainer) {
const showcaseItems = showcaseContainer.querySelectorAll('.showcase-item');
showcaseContainer.addEventListener('click', (event) => {
const header = event.target.closest('.showcase-header');
if (!header) return; // Exit if the click was not on a header
const currentItem = header.closest('.showcase-item');
if (!currentItem) return;
const isExpanded = currentItem.classList.contains('expanded');
// Close all other items
showcaseItems.forEach(item => {
if (item !== currentItem) {
item.classList.remove('expanded');
}
});
// Toggle the clicked item
if (!isExpanded) {
currentItem.classList.add('expanded');
} else {
currentItem.classList.remove('expanded');
}
});
}
});