aboutsummaryrefslogtreecommitdiff
path: root/src/component/ImageBackground.astro
diff options
context:
space:
mode:
authorWilliam Hergès <william@herges.fr>2025-08-09 16:26:34 +0200
committerWilliam Hergès <william@herges.fr>2025-08-09 16:26:34 +0200
commit8f826e1843fcfd210fa036196a9efa4a4f7fe144 (patch)
treee42f5da130f48e70579bb887c605c3aa08616f1d /src/component/ImageBackground.astro
parentb3afbbd330f7c2460407f05367041f1e4e394a8a (diff)
style(background): rename component into MosaicBackground
Diffstat (limited to 'src/component/ImageBackground.astro')
-rw-r--r--src/component/ImageBackground.astro49
1 files changed, 0 insertions, 49 deletions
diff --git a/src/component/ImageBackground.astro b/src/component/ImageBackground.astro
deleted file mode 100644
index d568172..0000000
--- a/src/component/ImageBackground.astro
+++ /dev/null
@@ -1,49 +0,0 @@
----
-const { height = "400" } = Astro.props;
----
-
-<div class="bg" data-height={height}>
- <slot />
-</div>
-
-<script>
- window.onload = () => {
- // because Astro doesn't support defer
- document.querySelectorAll(".bg").forEach((e) => {
- const children = e.children;
- const max = e.clientWidth;
- const height = e.getAttribute("data-height");
- const newChildren = [];
- console.log(e.hasAttribute("data-height"));
-
- let line = document.createElement("div");
- let currentWidth = 0;
- let i = 0;
-
- const fn = () => {
- let current = children[i++];
- console.log(current.getBoundingClientRect().width, current.getBoundingClientRect().height);
- 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();
- // setting height
- console.log(currentWidth);
- let h = (max * height) / currentWidth;
- console.log(`${h}px`);
- line.style.height = `${h - 1}px`;
- newChildren.push(line);
- if (i < children.length) {
- line = document.createElement("div");
- currentWidth = 0;
- }
- }
- e.replaceChildren(...newChildren);
- });
- };
-</script>