-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcard-hover.js
More file actions
79 lines (67 loc) · 2.31 KB
/
Copy pathcard-hover.js
File metadata and controls
79 lines (67 loc) · 2.31 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
<script>
// JavaScript to handle card hover effects for cards with images
document.addEventListener('DOMContentLoaded', function() {
// Find all cards
const cards = document.querySelectorAll('.card');
cards.forEach(card => {
const paragraphs = card.querySelectorAll('p');
// If card has only one paragraph (with image)
if (paragraphs.length === 1) {
const p = paragraphs[0];
const img = p.querySelector('img');
if (img) {
// Get all text nodes
const textContent = Array.from(p.childNodes)
.filter(node => node.nodeType === Node.TEXT_NODE)
.map(node => node.textContent.trim())
.filter(text => text.length > 0)
.join(' ');
if (textContent) {
// Create overlay div for description
const overlay = document.createElement('div');
overlay.className = 'card-description-overlay';
overlay.textContent = textContent;
card.appendChild(overlay);
// Remove text nodes completely
Array.from(p.childNodes).forEach(node => {
if (node.nodeType === Node.TEXT_NODE && node.textContent.trim().length > 0) {
node.remove();
}
});
}
}
}
});
// Equalize heights of grid sections (documentation cards)
function equalizeGridHeights() {
const grids = document.querySelectorAll('.grid');
grids.forEach(grid => {
const sections = Array.from(grid.querySelectorAll(':scope > section, :scope > div'));
if (sections.length === 0) return;
// Reset heights
sections.forEach(section => {
section.style.height = 'auto';
});
// Group sections by row (based on offsetTop)
const rows = new Map();
sections.forEach(section => {
const top = section.offsetTop;
if (!rows.has(top)) {
rows.set(top, []);
}
rows.get(top).push(section);
});
// Equalize heights within each row
rows.forEach(rowSections => {
const maxHeight = Math.max(...rowSections.map(s => s.offsetHeight));
rowSections.forEach(section => {
section.style.height = maxHeight + 'px';
});
});
});
}
// Run on load and resize
equalizeGridHeights();
window.addEventListener('resize', equalizeGridHeights);
});
</script>