Skip to content

Commit 2512b24

Browse files
committed
Fix sizing of media elements to allow for superscaling
1 parent 1118ed9 commit 2512b24

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

assets/common.css

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@
113113
var(--transition-timing);
114114

115115
/* Media Sizes */
116-
--max-media-width: clamp(300px, 60vw, 1000px);
116+
--media-width: clamp(300px, 60vw, 1000px);
117117
--max-media-height: 1200px;
118118
--max-media-width-big: clamp(70vw, 80vw, 800px);
119119
--max-media-height-big: 70vh;
120120
--max-media-width-small: clamp(25vw, 30vw, 250px);
121121
--max-media-height-small: 30vh;
122122

123123
@media (max-width: 768px) {
124-
--max-media-width: 100%;
124+
--media-width: 100%;
125125
}
126126

127127
/* Misc */
@@ -372,10 +372,14 @@ img,
372372
video,
373373
iframe {
374374
height: auto;
375-
max-width: var(--max-media-width);
376-
max-height: var(--max-media-height);
375+
width: var(--media-width);
377376
border-radius: var(--radius-xl);
378377
border: var(--border-standard);
378+
379+
&.media-tall {
380+
width: auto;
381+
height: var(--max-media-height);
382+
}
379383
}
380384

381385
.noborder {
@@ -496,7 +500,7 @@ ul {
496500
iframe {
497501
display: block;
498502
border: none;
499-
width: var(--max-media-width);
503+
width: var(--media-width);
500504
height: 500px;
501505

502506
&.homepage {

assets/common.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,34 @@ const forceLightMode = false;
9292
darkQuery.addEventListener("change", updateLightMode);
9393
});
9494
})();
95+
96+
// Add 'tall' class to media elements exceeding --max-media-height
97+
(function handleTallMedia() {
98+
function getMaxMediaHeight() {
99+
// Get the value of --max-media-height from the root element (in px)
100+
const root = document.documentElement;
101+
const value = getComputedStyle(root).getPropertyValue('--max-media-height').trim();
102+
// Parse value (assume px, fallback to 0 if not found)
103+
if (value.endsWith('px')) {
104+
return parseFloat(value);
105+
}
106+
return 0;
107+
}
108+
109+
function updateTallMediaClasses() {
110+
const maxHeight = getMaxMediaHeight();
111+
if (!maxHeight) return;
112+
document.querySelectorAll('img, video, iframe').forEach(function (el) {
113+
// Use offsetHeight for rendered height
114+
if (el.offsetHeight > maxHeight) {
115+
el.classList.add('media-tall');
116+
} else {
117+
el.classList.remove('media-tall');
118+
}
119+
});
120+
}
121+
122+
window.addEventListener("DOMContentLoaded", updateTallMediaClasses);
123+
window.addEventListener("load", updateTallMediaClasses);
124+
window.addEventListener("resize", updateTallMediaClasses);
125+
})();

0 commit comments

Comments
 (0)