# Bouncing ball loader

> A ball that drops, squashes flat on the floor and stretches as it springs back up, with a shadow that follows.

- Category: [Loaders](https://library.aimran.es/components/loaders)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/css-squash
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Squash and stretch is one of the first principles animators learn, and this bouncing ball shows it off nicely. That makes it a fun wink on an animation studio’s portfolio, and a natural fit for a sports shop selling balls and rackets or a gym’s class booking page. The shadow grows as the ball nears the floor.

It needs vertical space, about twice its width, so give it a tall spot. A single strong color works best, since the ball and its shadow share it. Slightly slower speeds make the squash more visible and the ball feel heavier.

## Code

### HTML

```html
<div class="ul-sq"><b></b></div>
```

### CSS

```css
.ul-sq {
  --c1: #0071e3;
  --c2: #8ec5ff;
  --s: 72px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --bg: #f5f5f7;
}

.ul-sq {
  position: relative;
  width: var(--s);
  height: calc(var(--s) * 2);
}

.ul-sq::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -4px;
  height: 8px;
  border-radius: 50%;
  background: var(--c1);
  opacity: .2;
  animation: ul-sq-s calc(0.9s / var(--k)) cubic-bezier(.5,0,.5,1) infinite alternate;
}

.ul-sq b {
  position: absolute;
  left: 25%;
  top: 0;
  width: 50%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--c1);
  transform-origin: 50% 100%;
  animation: ul-sq calc(0.9s / var(--k)) cubic-bezier(.5,0,.5,1) infinite alternate;
}

@keyframes ul-sq {
  0% {
    transform: translateY(0) scale(.95,1.05);
  }
  85% {
    transform: translateY(calc(var(--s) * 1.45)) scale(.9,1.15);
  }
  100% {
    transform: translateY(calc(var(--s) * 1.5)) scale(1.35,.7);
  }
}

@keyframes ul-sq-s {
  0% {
    transform: scale(.4);
    opacity: .08;
  }
  100% {
    transform: scale(1);
    opacity: .3;
  }
}
```

### React

```tsx
import type { CSSProperties } from "react";

const css = `
.ul-sq {
  position: relative;
  width: var(--s);
  height: calc(var(--s) * 2);
}

.ul-sq::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -4px;
  height: 8px;
  border-radius: 50%;
  background: var(--c1);
  opacity: .2;
  animation: ul-sq-s calc(0.9s / var(--k)) cubic-bezier(.5,0,.5,1) infinite alternate;
}

.ul-sq b {
  position: absolute;
  left: 25%;
  top: 0;
  width: 50%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--c1);
  transform-origin: 50% 100%;
  animation: ul-sq calc(0.9s / var(--k)) cubic-bezier(.5,0,.5,1) infinite alternate;
}

@keyframes ul-sq {
  0% {
    transform: translateY(0) scale(.95,1.05);
  }
  85% {
    transform: translateY(calc(var(--s) * 1.45)) scale(.9,1.15);
  }
  100% {
    transform: translateY(calc(var(--s) * 1.5)) scale(1.35,.7);
  }
}

@keyframes ul-sq-s {
  0% {
    transform: scale(.4);
    opacity: .08;
  }
  100% {
    transform: scale(1);
    opacity: .3;
  }
}
`;

export default function LoaderSquash() {
  return (
    <>
      <style>{css}</style>
      <div
        style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "72px",
          "--k": "1",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="ul-sq"><b></b></div>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Bouncing ball loader” block (Loaders) from AIMRAN Library to my project.

## What it is
A ball that drops, squashes flat on the floor and stretches as it springs back up, with a shadow that follows.

## Chosen settings
- Main color: #0071e3
- Secondary color: #8ec5ff
- Size: 72px (from 24 to 120px)
- Speed: 1x (from 0.5 to 2x)

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
import type { CSSProperties } from "react";

const css = `
.ul-sq {
  position: relative;
  width: var(--s);
  height: calc(var(--s) * 2);
}

.ul-sq::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -4px;
  height: 8px;
  border-radius: 50%;
  background: var(--c1);
  opacity: .2;
  animation: ul-sq-s calc(0.9s / var(--k)) cubic-bezier(.5,0,.5,1) infinite alternate;
}

.ul-sq b {
  position: absolute;
  left: 25%;
  top: 0;
  width: 50%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--c1);
  transform-origin: 50% 100%;
  animation: ul-sq calc(0.9s / var(--k)) cubic-bezier(.5,0,.5,1) infinite alternate;
}

@keyframes ul-sq {
  0% {
    transform: translateY(0) scale(.95,1.05);
  }
  85% {
    transform: translateY(calc(var(--s) * 1.45)) scale(.9,1.15);
  }
  100% {
    transform: translateY(calc(var(--s) * 1.5)) scale(1.35,.7);
  }
}

@keyframes ul-sq-s {
  0% {
    transform: scale(.4);
    opacity: .08;
  }
  100% {
    transform: scale(1);
    opacity: .3;
  }
}
`;

export default function LoaderSquash() {
  return (
    <>
      <style>{css}</style>
      <div
        style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "72px",
          "--k": "1",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="ul-sq"><b></b></div>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
