Skip to content

Commit 35830a7

Browse files
committed
Enhance mobile font sizing and touch interaction in secrets.css and secrets.js
- Updated CSS to disable touch actions and prevent text selection on mobile devices. - Introduced dynamic font sizing based on screen dimensions in secrets.js for improved readability. - Added event listeners to prevent zoom gestures and pinch zoom on mobile devices, enhancing user experience.
1 parent b0fb34e commit 35830a7

File tree

2 files changed

+58
-6
lines changed

2 files changed

+58
-6
lines changed

css/secrets.css

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ body {
33
position: relative;
44
background: #000;
55
margin: 0;
6-
touch-action: manipulation;
6+
touch-action: none;
77
-webkit-touch-callout: none;
88
-webkit-user-select: none;
99
-khtml-user-select: none;
1010
-moz-user-select: none;
1111
-ms-user-select: none;
1212
user-select: none;
13+
-webkit-text-size-adjust: none;
14+
-ms-text-size-adjust: none;
15+
text-size-adjust: none;
1316
}
1417

1518
/* Mobile flexbox container for lyrics */
@@ -142,7 +145,7 @@ svg {
142145
/* Mobile-specific lyric styling */
143146
.lyric-line.mobile {
144147
font-family: 'Roboto Slab', serif;
145-
font-size: 4.7vw;
148+
font-size: var(--mobile-font-size, 4vw);
146149
width: 100% !important;
147150
max-width: 100% !important;
148151
display: block !important;
@@ -182,7 +185,7 @@ svg {
182185

183186
.lyric-line.mobile {
184187
font-family: 'Roboto Slab', serif;
185-
font-size: 5.5vw;
188+
font-size: var(--mobile-font-size, 5vw);
186189
width: 100vw;
187190
left: 0 !important;
188191
line-height: 1.4;
@@ -195,7 +198,7 @@ svg {
195198
@media (max-width: 480px) {
196199
.lyric-line.mobile {
197200
font-family: 'Roboto Slab', serif;
198-
font-size: 6vw;
201+
font-size: var(--mobile-font-size, 5vw);
199202
width: 100vw;
200203
left: 0 !important;
201204
line-height: 1.5;
@@ -214,7 +217,7 @@ svg {
214217
@media (max-width: 360px) {
215218
.lyric-line.mobile {
216219
font-family: 'Roboto Slab', serif;
217-
font-size: 7vw;
220+
font-size: var(--mobile-font-size, 5vw);
218221
width: 100vw;
219222
left: 0 !important;
220223
line-height: 1.5;

js/secrets.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ var lyrics = [
1212
"when will i",
1313
"when will i",
1414
"see you again",
15-
"<break>",
1615
"tell me 'bout your day",
1716
"give me a call",
1817
"you tripped me",
@@ -76,6 +75,30 @@ function detectMobile() {
7675
}
7776

7877
function getMobilePosition() {
78+
// Calculate optimal font size based on screen dimensions and number of lyrics
79+
var totalLyrics = lyrics.length;
80+
var screenHeight = $(window).height();
81+
var screenWidth = $(window).width();
82+
83+
// Calculate available height (use almost all screen height)
84+
var availableHeight = screenHeight * 0.95; // Use 95% of screen height
85+
86+
// Minimal padding per lyric
87+
var paddingPerLyric = (screenHeight * 0.005); // 0.5vh in pixels (minimal padding)
88+
var availableForText = availableHeight - (paddingPerLyric * totalLyrics);
89+
90+
// Calculate line height for text only (excluding padding)
91+
var optimalLineHeight = availableForText / totalLyrics;
92+
93+
// Factor in line-height multiplier and convert to vw
94+
var optimalFontSizeVw = ((optimalLineHeight / 1.1) / screenWidth) * 100; // Even less aggressive division
95+
96+
// Apply reasonable constraints (allow larger fonts)
97+
var optimalFontSize = Math.max(3, Math.min(7, optimalFontSizeVw));
98+
99+
// Update CSS custom property for dynamic font sizing
100+
document.documentElement.style.setProperty('--mobile-font-size', optimalFontSize + 'vw');
101+
79102
// Zigzag pattern: left, center, right, center, left...
80103
var patternIndex = mobileLineIndex % 4;
81104

@@ -275,6 +298,32 @@ window.addEventListener('load', () => {
275298
}
276299
});
277300

301+
// Prevent zoom gestures
302+
document.addEventListener('gesturestart', function (e) {
303+
e.preventDefault();
304+
});
305+
306+
document.addEventListener('gesturechange', function (e) {
307+
e.preventDefault();
308+
});
309+
310+
document.addEventListener('gestureend', function (e) {
311+
e.preventDefault();
312+
});
313+
314+
// Prevent pinch zoom
315+
document.addEventListener('touchstart', function (e) {
316+
if (e.touches.length > 1) {
317+
e.preventDefault();
318+
}
319+
}, { passive: false });
320+
321+
document.addEventListener('touchmove', function (e) {
322+
if (e.touches.length > 1) {
323+
e.preventDefault();
324+
}
325+
}, { passive: false });
326+
278327

279328
window.onresize = function() {
280329
setup();

0 commit comments

Comments
 (0)