Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • {} & MotionProps
    • PanelBlocksProps

Index

Properties

Optional _dragX

_dragX: MotionValue<number>

Usually, dragging uses the layout project engine, and applies transforms to the underlying VisualElement. Passing MotionValues as _dragX and _dragY instead applies drag updates to these motion values. This allows you to manually control how updates from a drag gesture on an element is applied.

Optional _dragY

_dragY: MotionValue<number>

Usually, dragging uses the layout project engine, and applies transforms to the underlying VisualElement. Passing MotionValues as _dragX and _dragY instead applies drag updates to these motion values. This allows you to manually control how updates from a drag gesture on an element is applied.

Optional animate

animate: AnimationControls | TargetAndTransition | VariantLabels | boolean

Values to animate to, variant label(s), or AnimationControls.

library
// As values
<Frame animate={{ opacity: 1 }} />

// As variant
<Frame animate="visible" variants={variants} />

// Multiple variants
<Frame animate={["visible", "active"]} variants={variants} />

// AnimationControls
<Frame animate={animation} />
motion
// As values
<motion.div animate={{ opacity: 1 }} />

// As variant
<motion.div animate="visible" variants={variants} />

// Multiple variants
<motion.div animate={["visible", "active"]} variants={variants} />

// AnimationControls
<motion.div animate={animation} />

Optional custom

custom: any

Custom data to use to resolve dynamic variants differently for each animating component.

library
const variants = {
  visible: (custom) => ({
    opacity: 1,
    transition: { delay: custom * 0.2 }
  })
}

<Frame custom={0} animate="visible" variants={variants} />
<Frame custom={1} animate="visible" variants={variants} />
<Frame custom={2} animate="visible" variants={variants} />
motion
const variants = {
  visible: (custom) => ({
    opacity: 1,
    transition: { delay: custom * 0.2 }
  })
}

<motion.div custom={0} animate="visible" variants={variants} />
<motion.div custom={1} animate="visible" variants={variants} />
<motion.div custom={2} animate="visible" variants={variants} />

Optional drag

drag: boolean | "x" | "y"

Enable dragging for this element. Set to false by default. Set true to drag in both directions. Set "x" or "y" to only drag in a specific direction.

library
<Frame drag="x" />
motion
<motion.div drag="x" />

Optional dragConstraints

dragConstraints: false | Partial<BoundingBox2D> | RefObject<Element>

Applies constraints on the permitted draggable area.

It can accept an object of optional top, left, right, and bottom values, measured in pixels. This will define a distance the named edge of the draggable component.

Alternatively, it can accept a ref to another component created with React's useRef hook. This ref should be passed both to the draggable component's dragConstraints prop, and the ref of the component you want to use as constraints.

library
// In pixels
<Frame
  drag="x"
  dragConstraints={{ left: 0, right: 300 }}
/>

// As a ref to another component
function MyComponent() {
  const constraintsRef = useRef(null)

  return (
     <Frame ref={constraintsRef} width={400} height={400}>
         <Frame drag dragConstraints={constraintsRef} />
     </Frame>
  )
}
motion
// In pixels
<motion.div
  drag="x"
  dragConstraints={{ left: 0, right: 300 }}
/>

// As a ref to another component
const MyComponent = () => {
  const constraintsRef = useRef(null)

  return (
     <motion.div ref={constraintsRef}>
         <motion.div drag dragConstraints={constraintsRef} />
     </motion.div>
  )
}

Optional dragControls

dragControls: DragControls

Usually, dragging is initiated by pressing down on a component and moving it. For some use-cases, for instance clicking at an arbitrary point on a video scrubber, we might want to initiate dragging from a different component than the draggable one.

By creating a dragControls using the useDragControls hook, we can pass this into the draggable component's dragControls prop. It exposes a start method that can start dragging from pointer events on other components.

library
const dragControls = useDragControls()

function startDrag(event) {
  dragControls.start(event, { snapToCursor: true })
}

return (
  <>
    <Frame onTapStart={startDrag} />
    <Frame drag="x" dragControls={dragControls} />
  </>
)
motion
const dragControls = useDragControls()

function startDrag(event) {
  dragControls.start(event, { snapToCursor: true })
}

return (
  <>
    <div onPointerDown={startDrag} />
    <motion.div drag="x" dragControls={dragControls} />
  </>
)

Optional dragDirectionLock

dragDirectionLock: undefined | false | true

If true, this will lock dragging to the initially-detected direction. Defaults to false.

library
<Frame drag={true} dragDirectionLock={true} />
motion
<motion.div drag dragDirectionLock />

Optional dragElastic

dragElastic: boolean | number

The degree of movement allowed outside constraints. 0 = no movement, 1 = full movement. Set to 0.5 by default.

library
<Frame
  drag={true}
  dragConstraints={{ left: 0, right: 300 }}
  dragElastic={0.2}
/>
motion
<motion.div
  drag
  dragConstraints={{ left: 0, right: 300 }}
  dragElastic={0.2}
/>

Optional dragListener

dragListener: undefined | false | true

By default, if drag is defined on a component then an event listener will be attached to automatically initiate dragging when a user presses down on it.

By setting dragListener to false, this event listener will not be created.

library
const dragControls = useDragControls()

function startDrag(event) {
  dragControls.start(event, { snapToCursor: true })
}

return (
  <>
    <Frame onTapStart={startDrag} />
    <Frame
      drag="x"
      dragControls={dragControls}
      dragListener={false}
    />
  </>
)
motion
const dragControls = useDragControls()

function startDrag(event) {
  dragControls.start(event, { snapToCursor: true })
}

return (
  <>
    <div onPointerDown={startDrag} />
    <motion.div
      drag="x"
      dragControls={dragControls}
      dragListener={false}
    />
  </>
)

Optional dragMomentum

dragMomentum: undefined | false | true

Apply momentum from the pan gesture to the component when dragging finishes. Set to true by default.

library
<Frame
  drag={true}
  dragConstraints={{ left: 0, right: 300 }}
  dragMomentum={false}
/>
motion
<motion.div
  drag
  dragConstraints={{ left: 0, right: 300 }}
  dragMomentum={false}
/>

Optional dragPropagation

dragPropagation: undefined | false | true

Allows drag gesture propagation to child components. Set to false by default.

library
<Frame drag="x" dragPropagation={true} />
motion
<motion.div drag="x" dragPropagation />

Optional dragTransition

dragTransition: InertiaOptions

Allows you to change dragging inertia parameters. When releasing a draggable Frame, an animation with type inertia starts. The animation is based on your dragging velocity. This property allows you to customize it. See Inertia for all properties you can use.

library
<Frame
  drag={true}
  dragTransition={{ bounceStiffness: 600, bounceDamping: 10 }}
/>
motion
<motion.div
  drag
  dragTransition={{ bounceStiffness: 600, bounceDamping: 10 }}
/>

Optional exit

exit: TargetAndTransition | VariantLabels | TargetResolver

A target to animate to when this component is removed from the tree.

This component must be the first animatable child of an AnimatePresence to enable this exit animation.

This limitation exists because React doesn't allow components to defer unmounting until after an animation is complete. Once this limitation is fixed, the AnimatePresence component will be unnecessary.

library
import { Frame, AnimatePresence } from 'framer'

export function MyComponent(props) {
  return (
    <AnimatePresence>
       {props.isVisible && (
         <Frame
           initial={{ opacity: 0 }}
           animate={{ opacity: 1 }}
           exit={{ opacity: 0 }}
         />
       )}
    </AnimatePresence>
  )
}
motion
import { AnimatePresence, motion } from 'framer-motion'

export const MyComponent = ({ isVisible }) => {
  return (
    <AnimatePresence>
       {isVisible && (
         <motion.div
           initial={{ opacity: 0 }}
           animate={{ opacity: 1 }}
           exit={{ opacity: 0 }}
         />
       )}
    </AnimatePresence>
  )
}

Optional inherit

inherit: undefined | false | true

Optional initial

initial: boolean | Target | VariantLabels

Properties, variant label or array of variant labels to start in.

Set to false to initialise with the values in animate (disabling the mount animation)

library
// As values
<Frame initial={{ opacity: 1 }} />

// As variant
<Frame initial="visible" variants={variants} />

// Multiple variants
<Frame initial={["visible", "active"]} variants={variants} />

// As false (disable mount animation)
<Frame initial={false} animate={{ opacity: 0 }} />
motion
// As values
<motion.div initial={{ opacity: 1 }} />

// As variant
<motion.div initial="visible" variants={variants} />

// Multiple variants
<motion.div initial={["visible", "active"]} variants={variants} />

// As false (disable mount animation)
<motion.div initial={false} animate={{ opacity: 0 }} />

Optional layout

layout: boolean | "position"

If true, this component will automatically animate to its new position when its layout changes.

<motion.div layout />

This will perform a layout animation using performant transforms. Part of this technique involved animating an element's scale. This can introduce visual distortions on children, boxShadow and borderRadius.

To correct distortion on immediate children, add layout to those too.

boxShadow and borderRadius will automatically be corrected if they are already being animated on this component. Otherwise, set them directly via the initial prop.

If layout is set to "position", the size of the component will change instantly and only its position will animate.

Optional layoutId

layoutId: undefined | string

Enable shared layout transitions between components for children of AnimateSharedLayout.

When a component with a layoutId is removed from the React tree, and then added elsewhere, it will visually animate from the previous component's bounding box and its latest animated values.

<AnimateSharedLayout>
  {items.map(item => (
     <motion.li layout>
        {item.name}
        {item.isSelected && <motion.div layoutId="underline" />}
     </motion.li>
  ))}
</AnimateSharedLayout>

If the previous component remains in the tree it will either get hidden immediately or, if type="crossfade" is set on AnimateSharedLayout, it will crossfade to the new component.

Optional onMeasureDragConstraints

onMeasureDragConstraints: undefined | ((constraints: BoundingBox2D) => BoundingBox2D | void)

If dragConstraints is set to a React ref, this callback will call with the measured drag constraints.

Optional staggerChildren

staggerChildren: undefined | number

Optional static

static: undefined | false | true
internal

Set to true to block rendering motion values (animate, gestures, etcetera) on the component. This can be used to temporarily disable animations for performance reasons.

Optional style

style: MotionStyle
library

The React DOM style prop, useful for setting CSS properties that aren't explicitly exposed by Frame props.

<Frame style={{ mixBlendMode: "difference" }}  />
motion

The React DOM style prop, enhanced with support for MotionValues and separate transform values.

export const MyComponent = () => {
  const x = useMotionValue(0)

  return <motion.div style={{ x, opacity: 1, scale: 0.5 }} />
}

Optional transition

transition: Transition

Default transition. If no transition is defined in animate, it will use the transition defined here.

library
const spring = {
  type: "spring",
  damping: 10,
  stiffness: 100
}

<Frame transition={spring} animate={{ scale: 1.2 }} />
motion
const spring = {
  type: "spring",
  damping: 10,
  stiffness: 100
}

<motion.div transition={spring} animate={{ scale: 1.2 }} />

Optional variants

variants: Variants

Variants allow you to define animation states and organise them by name. They allow you to control animations throughout a component tree by switching a single animate prop.

Using transition options like delayChildren and staggerChildren, you can orchestrate when children animations play relative to their parent.

library

After passing variants to one or more Frame's variants prop, these variants can be used in place of values on the animate, initial, whileTap and whileHover props.

const variants = {
  active: {
    backgroundColor: "#f00"
  },
  inactive: {
    backgroundColor: "#fff",
    transition: { duration: 2 }
  }
}

<Frame variants={variants} animate="active" />
motion

After passing variants to one or more motion component's variants prop, these variants can be used in place of values on the animate, initial, whileTap and whileHover props.

const variants = {
  active: {
      backgroundColor: "#f00"
  },
  inactive: {
    backgroundColor: "#fff",
    transition: { duration: 2 }
  }
}

<motion.div variants={variants} animate="active" />

Optional whileHover

whileHover: string | TargetAndTransition

Properties or variant label to animate to while the hover gesture is recognised.

library
<Frame whileHover={{ scale: 1.2 }} />
motion
<motion.div whileHover={{ scale: 1.2 }} />

Optional whileTap

whileTap: string | TargetAndTransition

Properties or variant label to animate to while the component is pressed.

library
<Frame whileTap={{ scale: 0.8 }} />
motion
<motion.div whileTap={{ scale: 0.8 }} />

Methods

Optional onAnimationComplete

  • onAnimationComplete(): void
  • Callback when animation defined in animate is complete.

    library
    function onComplete() {
      console.log("Animation completed")
    }
    
    <Frame animate={{ x: 100 }} onAnimationComplete={onComplete} />
    motion
    function onComplete() {
      console.log("Animation completed")
    }
    
    <motion.div animate={{ x: 100 }} onAnimationComplete={onComplete} />

    Returns void

Optional onAnimationStart

  • onAnimationStart(): void
  • Callback when animation defined in animate begins.

    library
    function onStart() {
      console.log("Animation completed")
    }
    
    <Frame animate={{ x: 100 }} onAnimationStart={onStart} />
    motion
    function onStart() {
      console.log("Animation completed")
    }
    
    <motion.div animate={{ x: 100 }} onAnimationStart={onStart} />

    Returns void

Optional onDirectionLock

  • onDirectionLock(axis: "x" | "y"): void
  • Callback function that fires a drag direction is determined.

    library
    function onDirectionLock(axis) {
      console.log(axis)
    }
    
    <Frame
      drag
      dragDirectionLock
      onDirectionLock={onDirectionLock}
    />
    motion
    <motion.div
      drag
      dragDirectionLock
      onDirectionLock={axis => console.log(axis)}
    />

    Parameters

    • axis: "x" | "y"

    Returns void

Optional onDrag

  • onDrag(event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo): void
  • Callback function that fires when the component is dragged.

    library
    function onDrag(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <Frame drag onDrag={onDrag} />
    motion
    <motion.div
      drag
      onDrag={
        (event, info) => console.log(info.point.x, info.point.y)
      }
    />

    Parameters

    • event: MouseEvent | TouchEvent | PointerEvent
    • info: PanInfo

    Returns void

Optional onDragEnd

  • onDragEnd(event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo): void
  • Callback function that fires when dragging ends.

    library
    function onDragEnd(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <Frame drag onDragEnd={onDragEnd} />
    motion
    <motion.div
      drag
      onDragEnd={
        (event, info) => console.log(info.point.x, info.point.y)
      }
    />

    Parameters

    • event: MouseEvent | TouchEvent | PointerEvent
    • info: PanInfo

    Returns void

Optional onDragStart

  • onDragStart(event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo): void
  • Callback function that fires when dragging starts.

    library
    function onDragStart(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <Frame drag onDragStart={onDragStart} />
    motion
    <motion.div
      drag
      onDragStart={
        (event, info) => console.log(info.point.x, info.point.y)
      }
    />

    Parameters

    • event: MouseEvent | TouchEvent | PointerEvent
    • info: PanInfo

    Returns void

Optional onDragTransitionEnd

  • onDragTransitionEnd(): void
  • Callback function that fires when drag momentum/bounce transition finishes.

    library
    function onDragTransitionEnd() {
      console.log('drag transition has ended')
    }
    
    <Frame
      drag
      onDragTransitionEnd={onDragTransitionEnd}
    />
    motion
    <motion.div
      drag
      onDragTransitionEnd={() => console.log('Drag transition complete')}
    />

    Returns void

Optional onHoverEnd

  • onHoverEnd(event: MouseEvent, info: EventInfo): void
  • Callback function that fires when pointer stops hovering over the component.

    library
    function onHoverEnd(event) {
      console.log("Hover ends")
    }
    
    <Frame onHoverEnd={onHoverEnd} />
    motion
    <motion.div onHoverEnd={() => console.log("Hover ends")} />

    Parameters

    • event: MouseEvent
    • info: EventInfo

    Returns void

Optional onHoverStart

  • onHoverStart(event: MouseEvent, info: EventInfo): void
  • Callback function that fires when pointer starts hovering over the component.

    library
    function onHoverStart(event) {
      console.log("Hover starts")
    }
    
    <Frame onHoverStart={onHoverStart} />
    motion
    <motion.div onHoverStart={() => console.log('Hover starts')} />

    Parameters

    • event: MouseEvent
    • info: EventInfo

    Returns void

Optional onLayoutAnimationComplete

  • onLayoutAnimationComplete(): void
  • A callback that will fire when a layout animation on this component completes.

    Returns void

Optional onPan

  • onPan(event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo): void
  • Callback function that fires when the pan gesture is recognised on this element.

    library
    function onPan(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <Frame onPan={onPan} />
    motion
    function onPan(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <motion.div onPan={onPan} />

    Parameters

    • event: MouseEvent | TouchEvent | PointerEvent

      The originating pointer event.

    • info: PanInfo

      A {@link PanInfo} object containing x and y values for:

      • point: Relative to the device or page.
      • delta: Distance moved since the last event.
      • offset: Offset from the original pan event.
      • velocity: Current velocity of the pointer.

    Returns void

Optional onPanEnd

  • onPanEnd(event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo): void
  • Callback function that fires when the pan gesture ends on this element.

    library
    function onPanEnd(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <Frame onPanEnd={onPanEnd} />
    motion
    function onPanEnd(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <motion.div onPanEnd={onPanEnd} />

    Parameters

    • event: MouseEvent | TouchEvent | PointerEvent

      The originating pointer event.

    • info: PanInfo

      A {@link PanInfo} object containing x/y values for:

      • point: Relative to the device or page.
      • delta: Distance moved since the last event.
      • offset: Offset from the original pan event.
      • velocity: Current velocity of the pointer.

    Returns void

Optional onPanSessionStart

  • onPanSessionStart(event: MouseEvent | TouchEvent | PointerEvent, info: EventInfo): void
  • Callback function that fires when we begin detecting a pan gesture. This is analogous to onMouseStart or onTouchStart.

    library
    function onPanSessionStart(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <Frame onPanSessionStart={onPanSessionStart} />
    motion
    function onPanSessionStart(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <motion.div onPanSessionStart={onPanSessionStart} />

    Parameters

    • event: MouseEvent | TouchEvent | PointerEvent

      The originating pointer event.

    • info: EventInfo

      An {@link EventInfo} object containing x/y values for:

      • point: Relative to the device or page.

    Returns void

Optional onPanStart

  • onPanStart(event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo): void
  • Callback function that fires when the pan gesture begins on this element.

    library
    function onPanStart(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <Frame onPanStart={onPanStart} />
    motion
    function onPanStart(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <motion.div onPanStart={onPanStart} />

    Parameters

    • event: MouseEvent | TouchEvent | PointerEvent

      The originating pointer event.

    • info: PanInfo

      A {@link PanInfo} object containing x/y values for:

      • point: Relative to the device or page.
      • delta: Distance moved since the last event.
      • offset: Offset from the original pan event.
      • velocity: Current velocity of the pointer.

    Returns void

Optional onTap

  • onTap(event: MouseEvent | TouchEvent | PointerEvent, info: TapInfo): void
  • Callback when the tap gesture successfully ends on this element.

    library
    function onTap(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <Frame onTap={onTap} />
    motion
    function onTap(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <motion.div onTap={onTap} />

    Parameters

    • event: MouseEvent | TouchEvent | PointerEvent

      The originating pointer event.

    • info: TapInfo

      An {@link TapInfo} object containing x and y values for the point relative to the device or page.

    Returns void

Optional onTapCancel

  • onTapCancel(event: MouseEvent | TouchEvent | PointerEvent, info: TapInfo): void
  • Callback when the tap gesture ends outside this element.

    library
    function onTapCancel(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <Frame onTapCancel={onTapCancel} />
    motion
    function onTapCancel(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <motion.div onTapCancel={onTapCancel} />

    Parameters

    • event: MouseEvent | TouchEvent | PointerEvent

      The originating pointer event.

    • info: TapInfo

      An {@link TapInfo} object containing x and y values for the point relative to the device or page.

    Returns void

Optional onTapStart

  • onTapStart(event: MouseEvent | TouchEvent | PointerEvent, info: TapInfo): void
  • Callback when the tap gesture starts on this element.

    library
    function onTapStart(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <Frame onTapStart={onTapStart} />
    motion
    function onTapStart(event, info) {
      console.log(info.point.x, info.point.y)
    }
    
    <motion.div onTapStart={onTapStart} />

    Parameters

    • event: MouseEvent | TouchEvent | PointerEvent

      The originating pointer event.

    • info: TapInfo

      An {@link TapInfo} object containing x and y values for the point relative to the device or page.

    Returns void

Optional onUpdate

  • onUpdate(latest: {}): void
  • Callback with latest motion values, fired max once per frame.

    library
    function onUpdate(latest) {
      console.log(latest.x, latest.opacity)
    }
    
    <Frame animate={{ x: 100, opacity: 0 }} onUpdate={onUpdate} />
    motion
    function onUpdate(latest) {
      console.log(latest.x, latest.opacity)
    }
    
    <motion.div animate={{ x: 100, opacity: 0 }} onUpdate={onUpdate} />

    Parameters

    • latest: {}
      • [key: string]: string | number

    Returns void

Optional onViewportBoxUpdate

  • onViewportBoxUpdate(box: AxisBox2D, delta: BoxDelta): void
  • A callback that fires whenever the viewport-relative bounding box updates.

    Parameters

    • box: AxisBox2D
    • delta: BoxDelta

    Returns void

Optional transformTemplate

  • transformTemplate(transform: TransformProperties, generatedTransform: string): string
  • By default, Framer Motion generates a transform property with a sensible transform order. transformTemplate can be used to create a different order, or to append/preprend the automatically generated transform property.

    library
    function transformTemplate({ x, rotate }) {
      return `rotate(${rotate}deg) translateX(${x}px)`
    }
    
    <Frame x={0} rotate={180} transformTemplate={transformTemplate} />
    motion
    <motion.div
      style={{ x: 0, rotate: 180 }}
      transformTemplate={
        ({ x, rotate }) => `rotate(${rotate}deg) translateX(${x}px)`
      }
    />

    Parameters

    • transform: TransformProperties

      The latest animated transform props.

    • generatedTransform: string

      The transform string as automatically generated by Framer Motion

    Returns string

Optional transformValues

  • transformValues<V>(values: V): V
  • This allows values to be transformed before being animated or set as styles.

    For instance, this allows custom values in Framer Library like size to be converted into width and height. It also allows us a chance to take a value like Color and convert it to an animatable color string.

    A few structural typing changes need making before this can be a public property:

    • Allow Target values to be appended by user-defined types (delete CustomStyles - does size throw a type error?)
    • Extract CustomValueType as a separate user-defined type (delete CustomValueType and animate a Color - does this throw a type error?).
    internal

    Type parameters

    • V: ResolvedValues

    Parameters

    • values: V

      -

    Returns V