Skip to content

AnimateFloat

A slow drift with nowhere to get to. It says that something is not fixed to the page (an illustration, a floating card, a mark above a hero), and it runs for as long as the page is open.

tsx
import { AnimateFloat } from 'neba';

<AnimateFloat>
  <Card>Not fixed to the page.</Card>
</AnimateFloat>;

Props

PropTypeDefaultDescription
staggersharednumber0How long after one child the next one starts, in milliseconds. 0 animates the box itself; anything above it moves the effect onto each child in turn
durationStepsharednumber0How much longer each successive child takes, in milliseconds. Negative speeds them up down the list, and never past zero
reversesharedbooleanfalseRuns the children from the last to the first. Only the order reverses
durationsharednumber3200How long one run takes, in milliseconds
delaysharednumber0How long before it starts, in milliseconds
easingstringThe easing curve, as CSS writes it. Defaults to the house curve
repeatsharednumber | 'infinite''infinite'How many times it runs
alternatesharedbooleanfalseRuns every other pass backwards, so a repeat returns instead of jumping
triggershared'mount' | 'visible' | 'hover' | 'manual''mount'What starts it. visible is on scrolling into view, hover is under the pointer (focus counts), manual is whatever play says
playbooleanRuns it when trigger is manual. Each false → true starts it over
oncesharedbooleantrueWith trigger="visible", whether it runs only the first time. Off, it runs again on every return
thresholdsharednumber0.2With trigger="visible", how much of the element has to be on screen, from 0 to 1
pausedsharedbooleanfalseHolds the animation where it is
from'top' | 'right' | 'bottom' | 'left''top'Which way it drifts
distancenumber | string'0.5rem'How far, at the top of the drift. Numbers are pixels
renderuseRender.RenderPropRenders something other than a div (render={<figure />}). Base UI's own escape hatch
childrenReactNodeWhat drifts

Every other <div> attribute passes through to the root. The settings shared by every Animate* are defined in prop conventions.

It repeats forever and turns round at both ends, so there is never a frame where it jumps back. There is no mode: a drift has no direction to be reversed.

It is translate rather than a transform, so it composes with anything the element is already scaled or rotated by.

Examples

from and distance

from is which way it drifts and distance is how far it gets: a CSS length, or a number of pixels. Short on purpose: past about a centimetre it stops reading as something resting and starts reading as something moving.

stagger

stagger puts a set of floating things out of step with each other, which is what stops four of them reading as one block. It works the same way here as on AnimateFade.

paused

paused holds the drift where it is, without unmounting anything.

Accessibility

  • A reduced-motion preference switches the animation off and the content sits where the layout put it.
  • Do not float a control. Something that is never quite where it was is harder to press, and this is the one effect in the set with no end.

Released under the MIT License