Skip to content

Commit d616f61

Browse files
committed
Enhance poem overlay functionality and styles for improved user interaction
- Updated CSS in secrets.css to refine the poem overlay appearance, including adjustments to z-index, background, and responsive design. - Modified JavaScript in secrets.js to improve the poem overlay toggle behavior, allowing for smoother transitions and better handling of existing overlays. - Increased dimensions and padding for better visual presentation of the poem container and text.
1 parent 2614e07 commit d616f61

File tree

2 files changed

+67
-39
lines changed

2 files changed

+67
-39
lines changed

css/secrets.css

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ svg {
1414
margin: 0;
1515
transform: rotate(0deg);
1616
transition: transform 5s, width 1s, height 1s;
17+
position: relative;
18+
z-index: 2;
19+
pointer-events: none; /* Allow clicks to pass through to overlay behind */
20+
}
21+
22+
.cell svg {
23+
pointer-events: auto; /* But keep flowers themselves clickable */
1724
}
1825

1926
.cell:hover {
@@ -27,28 +34,27 @@ svg {
2734
left: 0;
2835
width: 100vw;
2936
height: 100vh;
30-
background: rgba(34, 34, 34, 0.95);
37+
background: transparent;
3138
display: flex;
3239
align-items: center;
3340
justify-content: center;
3441
opacity: 0;
35-
transition: opacity 0.8s ease-in-out;
36-
z-index: 10000;
42+
z-index: 1;
3743
cursor: pointer;
44+
transition: opacity 0.8s ease-in-out;
3845
}
3946

4047
.poem-overlay.visible {
4148
opacity: 1;
4249
}
4350

4451
.poem-container {
45-
max-width: 600px;
46-
max-height: 80vh;
47-
padding: 3rem;
52+
max-width: 800px;
53+
max-height: 90vh;
54+
padding: 4rem;
4855
text-align: center;
4956
overflow-y: auto;
50-
background: rgba(34, 34, 34, 0.8);
51-
border: 1px solid #f8f8f6;
57+
background: transparent;
5258
}
5359

5460
.poem-title {
@@ -64,32 +70,32 @@ svg {
6470
.poem-text {
6571
color: #f8f8f6;
6672
font-family: 'Roboto Slab', serif;
67-
font-size: 1.25em;
68-
line-height: 1.5;
73+
font-size: 1.5em;
74+
line-height: 1.6;
6975
margin: 1em 0;
70-
margin-bottom: 2rem;
76+
margin-bottom: 3rem;
7177
text-align: left;
7278
white-space: pre-line;
7379
}
7480

7581
.poem-close {
7682
color: #a6a9ac;
7783
font-family: 'Roboto Slab', serif;
78-
font-size: 0.9rem;
84+
font-size: 1rem;
7985
font-style: italic;
80-
opacity: 0.7;
81-
animation: pulse 2s infinite;
86+
opacity: 0.5;
87+
animation: pulse 3s infinite;
8288
}
8389

8490
@keyframes pulse {
85-
0%, 100% { opacity: 0.7; }
86-
50% { opacity: 0.3; }
91+
0%, 100% { opacity: 0.5; }
92+
50% { opacity: 0.2; }
8793
}
8894

8995
/* Mobile responsive */
9096
@media (max-width: 768px) {
9197
.poem-container {
92-
max-width: 90vw;
98+
max-width: 95vw;
9399
padding: 2rem;
94100
}
95101

@@ -98,6 +104,6 @@ svg {
98104
}
99105

100106
.poem-text {
101-
font-size: 1em;
107+
font-size: 1.2em;
102108
}
103109
}

js/secrets.js

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ window.onresize = function() {
119119
function setup() {
120120
var height = $('body').height();
121121
var width = $('body').width();
122-
var svgSize = 150;
123-
var padding = 20;
122+
var svgSize = 120;
123+
var padding = 30;
124124

125125
var isMobile = window.matchMedia("only screen and (max-width: 850px)").matches ||
126126
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
@@ -130,8 +130,9 @@ function setup() {
130130
padding = 40;
131131
}
132132

133-
var rows = Math.floor(height / svgSize);
134-
var cols = Math.floor(width / svgSize);
133+
var rows = Math.floor(height / svgSize) + 1.5; // Add 1.5 rows: 1 full + 0.5 for 1/4 cutoff
134+
rows = Math.ceil(rows); // Round up to ensure we have enough rows
135+
var cols = Math.floor(width / svgSize) + 1; // Add extra column for better coverage
135136
var radius = Math.floor(Math.max(width, height) / Math.max(rows, cols)) / 2;
136137

137138
shapes = makeFlowers(radius);
@@ -167,10 +168,13 @@ function addSvgs(size, rows, cols) {
167168
}
168169

169170
function positionCells(cols, size) {
171+
// Add offset to cut off 1/4 of top row (show 3/4)
172+
var verticalOffset = -size / 6;
173+
170174
$(".cell").each(function (i, o) {
171175
var r = Math.floor(i / cols);
172176
var c = i % cols;
173-
var top = size * r;
177+
var top = (size * r) + verticalOffset;
174178
var left = size * c;
175179
// Offset odd rows
176180
if (r % 2) {
@@ -220,35 +224,53 @@ function pickFlower(flowers) {
220224

221225

222226
function toggleSVG(cell, two, shape) {
223-
var isEnlarged = cell.data("isEnlarged");
224-
225-
if (isEnlarged) {
226-
// Remove poem overlay and return to normal
227-
$('.poem-overlay').remove();
228-
$('.cell').data("isEnlarged", false);
227+
// Check if any poem is currently open
228+
var existingOverlay = $('.poem-overlay');
229+
230+
if (existingOverlay.length > 0) {
231+
// If poem is open, close it with fade out
232+
console.log('Closing existing poem via flower click');
233+
234+
// Use CSS transition instead of jQuery fadeOut
235+
existingOverlay.removeClass('visible');
236+
237+
setTimeout(() => {
238+
console.log('Fade out complete, removing element');
239+
existingOverlay.remove();
240+
$('.cell').data("isEnlarged", false);
241+
$(document).off('keydown.poem-overlay');
242+
}, 800);
229243
} else {
230-
// Show poem overlay without complex animations
244+
// If no poem is open, show a new one
245+
console.log('Opening new poem via flower click');
231246
var poem = getRandomPoem();
232247
var poemOverlay = $(`
233248
<div class="poem-overlay">
234249
<div class="poem-container">
235250
<h3 class="poem-title">${poem.title}</h3>
236251
<div class="poem-text">${poem.text.replace(/\n/g, '<br>')}</div>
237-
<div class="poem-close">click anywhere to close</div>
252+
<div class="poem-close">click any flower to close</div>
238253
</div>
239254
</div>
240255
`);
241256

242257
$('body').append(poemOverlay);
243258

244-
// Add click handler to close overlay with fade out animation
245-
poemOverlay.on('click', function() {
246-
var overlay = $(this);
247-
overlay.removeClass('visible');
248-
setTimeout(() => {
249-
overlay.remove();
250-
$('.cell').data("isEnlarged", false);
251-
}, 800); // Wait for fade out animation to complete
259+
// Add ESC key handler
260+
$(document).on('keydown.poem-overlay', function(e) {
261+
if (e.key === 'Escape' || e.keyCode === 27) {
262+
console.log('ESC key pressed, closing overlay');
263+
264+
// Use CSS transition instead of jQuery fadeOut
265+
poemOverlay.removeClass('visible');
266+
267+
setTimeout(() => {
268+
console.log('ESC fade out complete, removing element');
269+
poemOverlay.remove();
270+
$('.cell').data("isEnlarged", false);
271+
$(document).off('keydown.poem-overlay');
272+
}, 800);
273+
}
252274
});
253275

254276
// Fade in the poem

0 commit comments

Comments
 (0)