From 170229675d6450b926969789f1ca46ddced3f9a1 Mon Sep 17 00:00:00 2001 From: Mattias Bodlund Date: Mon, 18 Aug 2025 11:54:15 +0200 Subject: [PATCH] na --- app/assets/stylesheets/application.css | 4 +-- app/javascript/application.js | 50 ++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 2d11a71..6b5cf9e 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -553,11 +553,11 @@ main { line-height: 1.3; align-self: end; - /*min-height: 160px;*/ - + display: flex; flex-direction: column; justify-content: space-between; + gap: 0; transition: background-color 200ms ease-in-out, color 200ms ease-in-out; diff --git a/app/javascript/application.js b/app/javascript/application.js index cd6e9eb..a088e5d 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -203,13 +203,13 @@ function animateElementsSequentially(index = 0) { const relativePercentage = (percentage / maxPercentage) * 100 const calculatedHeight = (relativePercentage / 100) * containerHeight - const computedStyle = window.getComputedStyle(bar) - const minHeight = parseInt(computedStyle.minHeight) || 0 + const minHeight = getNaturalHeight(bar) let finalMinHeight = minHeight - if (bar.querySelector('.explanation')) { - finalMinHeight = Math.max(minHeight, 160) - } + + // if (bar.querySelector('.explanation')) { + // finalMinHeight = Math.max(minHeight, 160) + // } targetHeights[i] = Math.max(calculatedHeight, finalMinHeight) }) @@ -541,4 +541,42 @@ function typeWriterConsoleSequential(container, options = {}) { get isActive() { return isActive } } -} \ No newline at end of file +} + +function getNaturalHeight(el) { + // Save original inline styles + + const prevParent = { + display: el.style.display, + visibility: el.style.visibility + }; + + // Apply temporary styles to parent + el.style.display = "flex"; + + // Also handle hidden children + const childPrev = []; + for (let child of el.children) { + childPrev.push({ + display: child.style.display, + visibility: child.style.visibility, + position: child.style.position + }); + + child.style.display = "block"; // let CSS decide + + } + + // Measure + const height = el.scrollHeight; + + // Restore child styles + Array.from(el.children).forEach((child, i) => { + Object.assign(child.style, childPrev[i]); + }); + + // Restore parent styles + Object.assign(el.style, prevParent); + + return height; +}