diff options
| author | William Hergès <william@herges.fr> | 2025-08-09 17:23:35 +0200 |
|---|---|---|
| committer | William Hergès <william@herges.fr> | 2025-08-09 17:23:35 +0200 |
| commit | f4c971dc8769f845cc48443dab020cb2e9df661a (patch) | |
| tree | b7e38847e663fbd126a5fb875dfb2a0796af71c2 /src/component | |
| parent | 1b763e17ecbe46a3cee806a7177b0bd60e15bf44 (diff) | |
refactor(background): cleaner and more logical
Diffstat (limited to 'src/component')
| -rw-r--r-- | src/component/MosaicBackground.astro | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/component/MosaicBackground.astro b/src/component/MosaicBackground.astro index df81a25..c8e01f5 100644 --- a/src/component/MosaicBackground.astro +++ b/src/component/MosaicBackground.astro @@ -20,17 +20,14 @@ const { height = "400" } = Astro.props; let currentWidth = 0; let i = 0; - const fn = () => { - let current = children[i++]; - let ratio = current.clientWidth / current.clientHeight; - line.appendChild(current.cloneNode(true)); - currentWidth += ratio * height; - }; - while (i < children.length) { // adding elements - while (i < children.length && currentWidth <= max) fn(); - if (i < children.length) fn(); + while (i < children.length && currentWidth <= max) { + let current = children[i++]; + let ratio = current.clientWidth / current.clientHeight; + line.appendChild(current.cloneNode(true)); + currentWidth += ratio * height; + } // setting height let h = (max * height) / currentWidth; line.style.height = `${h - 0.01}px`; |
