PXD
v0.2.1-dev

Reveal

Fade an element in while it moves from an offset and optional blur into place. By default the animation runs on mount with no JavaScript observer involved; set trigger to viewport to hold it back until the element scrolls into view.

Default

Content that fades in
No observer is created in this mode.
<template>
  <PReveal>
    <PCard class="w-80">
      <div class="font-medium">Content that fades in</div>
      <div class="text-[13px] text-gray-600">No observer is created in this mode.</div>
    </PCard>
  </PReveal>
</template>

Direction

direction sets the edge the element travels from, so bottom means it starts below its resting place and settles upward.

From the top
From the bottom
From the left
From the right
<template>
  <PStack direction="vertical" :gap="4">
    <PReveal direction="top">
      <PCard>From the top</PCard>
    </PReveal>
    <PReveal direction="bottom">
      <PCard>From the bottom</PCard>
    </PReveal>
    <PReveal direction="left">
      <PCard>From the left</PCard>
    </PReveal>
    <PReveal direction="right">
      <PCard>From the right</PCard>
    </PReveal>
  </PStack>
</template>

Duration and Delay

A bare number is read as seconds; pass a string to carry your own unit. delay staggers a list — give each item its own value.

Plays over one second
Waits 300ms, then plays
Waits 600ms
<script setup>
const items = ['First', 'Second', 'Third']
</script>

<template>
  <PStack direction="vertical" :gap="4">
    <PReveal :duration="1" :delay="0">
      <PCard>Plays over one second</PCard>
    </PReveal>
    <PReveal duration="800ms" :delay="0.3">
      <PCard>Waits 300ms, then plays</PCard>
    </PReveal>
    <PReveal :delay="0.6">
      <PCard>Waits 600ms</PCard>
    </PReveal>
  </PStack>
</template>

Distance

distance is the initial offset in pixels.

Fades in place
Travellers further
<template>
  <PStack direction="vertical" :gap="4">
    <PReveal :distance="0">
      <PCard>Fades in place</PCard>
    </PReveal>
    <PReveal :distance="48">
      <PCard>Travellers further</PCard>
    </PReveal>
  </PStack>
</template>

On Viewport

trigger="viewport" holds the element at its first frame until it enters the viewport. rootMargin decides how early that happens, which is what staggers a long list as it scrolls past. The reveal is one-shot: once played, the element stops being observed and never replays. Where IntersectionObserver is unavailable, the element is left visible instead of waiting for a callback that can never arrive.

Plays once this card reaches the viewport
Each element plays on its own
And never replays
<template>
  <div class="h-200 overflow-scroll rounded-lg border border-dashed">
    <div class="flex h-150 flex-col justify-between">
      <PReveal trigger="viewport" root-margin="0px 0px -20% 0px">
        <PCard>Plays once this card reaches the viewport</PCard>
      </PReveal>
      <PReveal trigger="viewport" root-margin="0px 0px -20% 0px">
        <PCard>Each element plays on its own</PCard>
      </PReveal>
      <PReveal trigger="viewport" root-margin="0px 0px -20% 0px">
        <PCard>And never replays</PCard>
      </PReveal>
    </div>
  </div>
</template>

Props

NameTypeDefaultDescription
durationnumber | string0.5Animation duration. A bare number is seconds; a string passes its unit through.
delaynumber | string0Delay before the animation starts, in the same form as duration.
distancenumber | string16Initial offset in pixels along the reveal axis.
direction'top' | 'bottom' | 'left' | 'right'bottomEdge the element travels from.
trigger'mount' | 'viewport'mountmount plays on render without creating an observer; viewport waits for the element to enter the viewport.
rootElement | Document | null-Scrolling ancestor to observe against, null for the viewport.
rootMarginstring0pxMargin applied to root, which decides how early the animation starts.
thresholdnumber | number[]0Intersection ratio at which the element counts as visible.

Slots

NameDescription
defaultContent to reveal.

Source

Source