# shine

A glint that sweeps across a button, a card or an image on hover, on a timer or as it comes into view.

A soft bright band with a brighter core, width of the element’s length across, travels over the element at angle in duration seconds, easing in and out, clipped to its rounded corners, each one as CSS draws it. Between sweeps nothing is drawn and the element is just DOM.

Module `blocks`, category Blocks and cards. Import `@dioramajs/blocks/shine`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/blocks/src/shine.ts)

A white pricing card for a Team plan whose violet upgrade button catches a glint every three seconds.

```html title="index.html"
<div class="pricing">
  <article class="plan">
    <p class="tier">Team</p>
    <p class="price"><strong>$49</strong> per month</p>
    <ul>
      <li>Up to 25 editors</li>
      <li>Shared design library</li>
      <li>Version history for a year</li>
    </ul>
    <a class="upgrade" href="/pricing" data-dio="shine" data-dio-trigger="interval" data-dio-interval="3">Upgrade to Team</a>
  </article>
</div>
```

## Usage

Put it on: any element: a button, a link, a pricing card, a badge, an image.

`start()` registers `shine`, so the attribute alone puts it on an element.

```html
<a class="button" href="/signup" data-dio="shine">Start free trial</a>
```

In page transitions: A sweep fades with the page as it leaves.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `trigger` (rebuilds) | `data-dio-trigger` | `'hover' \| 'interval' \| 'view'` | `'hover'` | hover sweeps on pointer enter and keyboard focus; interval also sweeps on a timer while on screen, for a call to action; view sweeps once as it comes into view, for a badge or a plan. |
| `angle` | `data-dio-angle` | `number` 0 to 360° | `120` | Direction of the sweep, like a CSS gradient angle; 90 goes left to right. |
| `width` | `data-dio-width` | `number` 0.05 to 1 | `0.35` | Width of the band as a share of the element’s length along the sweep. |
| `color` | `data-dio-color` | `color` | `'#ffffff'` | Color of the band, any CSS color. |
| `duration` | `data-dio-duration` | `number` 0.2 to 4 s | `1.1` | Time one sweep takes. |
| `interval` | `data-dio-interval` | `number` 0 to 20 s | `4` | Pause between timed sweeps with the interval trigger; 0 sweeps on hover only. |
| `strength` | `data-dio-strength` | `number` 0 to 1 | `0.5` | Opacity of the band at its core; 0 hides it. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `trigger`: `hover`, `interval`, `view`
  - `hover` sweeps on pointer enter and keyboard focus.
  - `interval` also sweeps on a timer while on screen, for a call to action.
  - `view` sweeps once as it comes into view, for a badge or a plan.

## Inputs and frames

Reads [`opacity`](/docs/api/inputs#opacity), [`presence`](/docs/api/inputs#presence), [`size`](/docs/api/inputs#size). Draws only while something on it moves, then stops. Only during a sweep; none at rest and none while waiting for the next timed sweep. See [how a frame is decided](/docs/concepts/frames).

## Reduced motion and touch

With reduced motion it is off and the element shows as plain HTML. Off: neither the module nor the engine loads for it, and the element is unchanged.

Runs on every device. A tap sweeps like a hover; the interval and view triggers work as on desktop.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { shine: { reducedMotion: 'static' } } })
```

## Cost and quality

Loads 1.9 KB the first time a page uses it. GPU: One quad over the element, drawn only during a sweep. Memory: None beyond the quad.

See [the quality plugin](/docs/effects/quality).

## Recipes

### The featured plan on hover

On a pricing table, the plan you recommend can catch the light as the pointer comes over it. A narrower `width` and a lower `strength` keep the band subtle on a large card.

Three pricing plans on a warm page; the dark featured Studio plan glints when the pointer enters it.

```html title="index.html"
<div class="plans">
  <article class="option">
    <h3>Starter</h3>
    <p><strong>$0</strong> per month</p>
    <p>One project, community support.</p>
  </article>
  <article class="option featured" data-dio="shine" data-dio-width="0.25" data-dio-strength="0.3">
    <h3>Studio</h3>
    <p><strong>$29</strong> per month</p>
    <p>Unlimited projects, priority support.</p>
  </article>
  <article class="option">
    <h3>Agency</h3>
    <p><strong>$99</strong> per month</p>
    <p>Client workspaces and white labeling.</p>
  </article>
</div>
```

### A badge that glints as it shows up

The `view` trigger sweeps once the first time half of the element is in view. A warm `color` and a stronger `strength` suit a gold member badge or an award seal.

A gold member badge above a welcome message, sweeping once as it scrolls into view.

```html title="index.html"
<section class="member">
  <span class="badge" data-dio="shine" data-dio-trigger="view" data-dio-color="#fff4cc" data-dio-strength="0.65" data-dio-duration="1.2">Gold member</span>
  <h3>Welcome back, Dana</h3>
  <p>Free shipping and early access to every drop are on for your account.</p>
</section>
```

## Notes

The element stays DOM: the band draws over it on the canvas only during a sweep and is clipped to the element’s own `border-radius`, corner by corner, so pill buttons work too. A parent with `overflow: hidden` does not clip it, so keep the element fully inside such a parent. Between sweeps nothing is drawn, and the `interval` trigger waits on a timer without drawing frames. Timed sweeps pause while the element is off screen or the tab is hidden.

Keyboard focus on the element or a control inside it sweeps like a hover, and a tap sweeps on touch screens.

Under reduced motion neither the module nor the engine loads for it, and the element stays as it is.

`trigger` rebuilds the effect when it changes; the other params change live and apply to the next sweep.

## Related

- [beam](/docs/effects/beam.md): A light beam that runs around the rounded border of a feature card, an input field or a highlight box.
- [glow](/docs/effects/glow.md): A spotlight that follows the pointer over a grid of cards and lights up their borders, as on SaaS and developer tool sites.
- [ambient](/docs/effects/ambient.md): A soft glow in the colors of the frame around a video or an image, like ambient mode.
- [beat](/docs/effects/beat.md): A cover, logo, card or play button that pulses with the music of a page player: it scales, shakes and glows, or sends out rings, on the beat.
- [bend](/docs/effects/bend.md): Scroll speed bends the image like paper and splits its color channels.
- [book](/docs/effects/book.md): A cover image made a 3D book that turns to show its spine and opens on hover.
- [box](/docs/effects/box.md): A product box built from pictures of its faces: turn it, tilt it, open its lid.
- [coin](/docs/effects/coin.md): A coin, medal or token struck from a logo or a photo: it turns, catches the light and flips over.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
