LayerwiseLayerwise
  • Features
  • Pricing
  • Templates
  • Docs
DownloadDownload
FeaturesPricingTemplatesDocsAI Website BuilderVibe CodingPersonal Software
DownloadDownload
  1. Glossary
  2. /
  3. State transitions

Direction-aware transition

Also called directional transition or directional navigation

A transition that slides new content in from the side you are heading toward, so going forward and going back move in opposite directions.

import { useState } from 'react';
import { AnimatePresence, motion, useReducedMotion } from 'motion/react';

const steps = [
  { title: 'Create your account', text: 'Start with your work email.' },
  { title: 'Name your workspace', text: 'Your teammates will see this name.' },
  { title: 'Invite your team', text: 'Add people now or any time later.' }
];

const DISTANCE = 40;

// direction is 1 going forward and -1 going back.
const slide = {
  enter: (direction: number) => ({ x: direction * DISTANCE, opacity: 0 }),
  center: { x: 0, opacity: 1 },
  exit: (direction: number) => ({ x: direction * -DISTANCE, opacity: 0 })
};

export function SignupSteps() {
  const [[step, direction], setStep] = useState([0, 1]);
  const reduceMotion = useReducedMotion();
  // Later steps sit on the left in right-to-left layouts; reduced motion keeps only the fade.
  const rtl = document.documentElement.dir === 'rtl';
  const custom = reduceMotion ? 0 : rtl ? -direction : direction;
  const current = steps[step]!;
  const last = step === steps.length - 1;
  const go = (next: number) => setStep([next, next > step ? 1 : -1]);

  return (
    <div className='relative w-80 overflow-hidden rounded-2xl border bg-background p-6'>
      {/* The leaving step needs the new direction too, so pass it to AnimatePresence. */}
      <AnimatePresence mode='popLayout' initial={false} custom={custom}>
        <motion.div
          key={step}
          custom={custom}
          variants={slide}
          initial='enter'
          animate='center'
          exit='exit'
          transition={{ duration: 0.25, ease: [0.23, 1, 0.32, 1] }}
        >
          <h3 className='font-semibold'>{current.title}</h3>
          <p className='mt-1 text-sm text-muted-foreground'>{current.text}</p>
        </motion.div>
      </AnimatePresence>
      <div className='mt-6 flex justify-between text-sm font-medium *:rounded-full *:border *:px-4 *:py-2 *:disabled:opacity-40'>
        <button
          type='button'
          disabled={step === 0}
          onClick={() => go(step - 1)}
        >
          Back
        </button>
        <button type='button' disabled={last} onClick={() => go(step + 1)}>
          Next
        </button>
      </div>
    </div>
  );
}
Add direction-aware transitions to the 3-step signup wizard: moving forward should slide the current step 40px to the left while it fades out and bring the next step in from 40px on the right, and going back should do the reverse. Use 250ms with ease-out, keep the container height stable during the slide, mirror the direction for right-to-left layouts, and use a plain crossfade when prefers-reduced-motion is set.

Paste into Layerwise or any AI coding tool.

What is Direction-aware transition?

In a direction-aware transition, the animation depends on where you are going. Tap Next and the current step slides out to the left while the next one enters from the right. Tap Back and everything reverses. The motion matches the map people already have in their heads, with earlier steps on the left and later ones on the right.

Use it for steppers, onboarding flows, carousels, image galleries, tabs, and calendars that page through months. When every change slides the same way, going back feels like moving forward again, and people lose their sense of place.

To build it, compare the new index with the previous one to get a direction of 1 or -1, then use that value in both the entering and the exiting animation. In Motion, pass it to the custom prop of AnimatePresence too, because an element that is leaving can no longer receive new props. In right-to-left languages, flip the direction.

Often confused with

Slide in
A slide-in always enters from the same side. A direction-aware transition picks the side based on whether you move forward or back.

Related terms

All terms

Stepper

A multi-step flow with a row of numbered steps, like Account, Profile, Done, that shows where you are and how many steps are left.

Carousel

A row of slides shown one at a time and moved with arrows, dots, swipes, or a timer, to fit several images or cards in one spot.

Page transition

An animation that plays when you move from one page or screen to another, such as the old page fading out as the new one fades in.

Spatial consistency

Moving elements in ways that match where things live in the interface, so people can tell where an item went and how to find it again.

Build it with Layerwise

Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.

DownloadDownloadRead the docs
LayerwiseLayerwise

Build full-stack web apps in minutes with AI.

Product

  • Features
  • Pricing
  • Download
  • Templates

Solutions

  • AI Website Builder
  • Vibe Coding
  • Personal Software

Resources

  • Documentation
  • Changelog
  • Blog
  • Vibe Coding Glossary
  • llms.txt
  • llms-full.txt

Company

  • About
  • Contact

Legal

  • Privacy
  • Analytics Privacy
  • Terms
  • Security
  • Abuse

© 2026 Layerwise. All rights reserved.

Entrances & exits

  • Fade in
  • Slide in
  • Scale in
  • Pop in
  • Blur in
  • Reveal animation
  • Enter and exit animations

Timing & sequencing

  • Duration
  • Delay
  • Keyframes
  • Tweening
  • Stagger
  • Orchestration
  • Fill mode
  • Stepped animation
  • Looping animation
  • Yoyo animation

Easing

  • Easing
  • Linear easing
  • Ease-in
  • Ease-out
  • Ease-in-out
  • Cubic-bezier
  • Asymmetric easing
  • Overshoot easing

Springs & physics

  • Spring animation
  • Stiffness
  • Damping
  • Mass
  • Bounce
  • Velocity
  • Momentum
  • Interruptible animation
  • Rubber-banding

Transforms

  • Translate
  • Scale
  • Rotate
  • Skew
  • 3D flip
  • Perspective
  • Transform origin
  • Origin-aware animation

State transitions

  • Crossfade
  • Morph
  • Shared element transition
  • Layout animation
  • Height auto animation
  • Direction-aware transition
  • Continuity transition
  • Page transition
  • View Transitions API

Scroll effects

  • Scroll reveal
  • Scroll-driven animation
  • Parallax scrolling
  • Scrollytelling
  • Scroll pinning
  • Horizontal scroll section
  • Scroll progress bar
  • Scroll snap
  • Smooth scrolling

Interaction feedback

  • Hover effect
  • Press feedback
  • Ripple effect
  • Shake animation
  • Hold to confirm
  • Drag gesture
  • Drag to reorder
  • Swipe to dismiss
  • Pull to refresh
  • Magnetic button
  • Custom cursor
  • 3D tilt card
  • Spotlight card

Text effects

  • Typewriter effect
  • Text scramble
  • Split text animation
  • Text morph
  • Rotating words
  • Gradient text
  • Shimmer text
  • Number ticker
  • Tabular numbers
  • Underline animation

Loops & ambient motion

  • Marquee
  • Pulse animation
  • Float animation
  • Orbit animation
  • Idle animation
  • Particle background
  • Border beam
  • Confetti
  • Animated gradient

Visual effects

  • Blur
  • Clip-path
  • Mask
  • Before/after slider
  • SVG line drawing
  • Lottie animation

Motion principles

  • Purposeful animation
  • Anticipation
  • Follow-through
  • Squash and stretch
  • Perceived performance
  • Frequency of use
  • Spatial consistency
  • Reduced motion

Animation performance

  • Frame rate (FPS)
  • Jank
  • GPU acceleration
  • will-change
  • Layout thrashing

Layout

  • Hero section
  • Above the fold
  • Sticky header
  • Sidebar
  • Bento grid
  • Card
  • Flexbox
  • CSS Grid
  • Padding vs margin
  • Responsive design
  • Container
  • Masonry layout
  • Split screen
  • Z-index
  • Overflow

Components

  • Button variants
  • Modal
  • Drawer
  • Popover
  • Tooltip
  • Dropdown menu
  • Context menu
  • Toast notification
  • Tabs
  • Segmented control
  • Accordion
  • Carousel
  • Command palette
  • Combobox
  • Toggle switch
  • Checkbox
  • Radio button
  • Date picker
  • Breadcrumb
  • Pagination
  • Infinite scroll
  • Badge
  • Avatar stack
  • Empty state
  • Skeleton screen
  • Spinner
  • Progress bar
  • Data table
  • Stepper
  • Floating label
  • Inline validation
  • Alert banner
  • Tag input

States & patterns

  • Interaction states
  • Focus ring
  • Loading state
  • Optimistic UI
  • Debounce
  • Lazy loading
  • Dark mode
  • Micro-interaction
  • Affordance
  • Undo
  • Drag and drop
  • Keyboard shortcut

Visual styles

  • Glassmorphism
  • Liquid glass
  • Neumorphism
  • Claymorphism
  • Neo-brutalism
  • Skeuomorphism
  • Flat design
  • Mesh gradient
  • Aurora background
  • Grain texture
  • Glow effect
  • Drop shadow
  • Border radius
  • Grid background
  • Typographic hierarchy
  • Accent color
  • Color contrast

Vibe coding & AI

  • Vibe coding
  • Prompt
  • Context window
  • Token
  • AI agent
  • Tool call
  • Hallucination
  • Diff
  • Live preview
  • Checkpoint
  • Git commit
  • Deploy
  • Frontend and backend
  • API
  • Database
  • Rules file
  • MCP
  • Plan mode
  • Visual edit
Step 1 of 3

Create your account

Pick a name and email.