1. Home
  2. /
  3. React-motion
  4. /
  5. Diagonal Slide Animation

Diagonal Slide Animation - React-motion Typing CST Test

Loading…

Diagonal Slide Animation — React-motion Code

Moves a div diagonally using React Motion spring physics.

# react_motion/demo/DiagonalSlide.jsx
import React from 'react';
import { Motion, spring } from 'react-motion';

function DiagonalSlide() {
	return (
		<Motion defaultStyle={{ x: 0, y: 0 }} style={{ x: spring(150), y: spring(150) }}>
		{style => (
		<div style={{ width: 100, height: 100, background: 'blue', transform: `translate(${style.x}px, ${style.y}px)` }} />
		)}
		</Motion>
	);
}

export default DiagonalSlide

React-motion Language Guide

React Motion is a popular animation library for React that uses physics-based animations to create smooth and natural transitions. It provides a simple API to animate components’ styles over time using spring dynamics rather than fixed durations.

Primary Use Cases

  • ▸Animating component style changes (e.g., width, height, opacity)
  • ▸Enter/exit animations for lists and items
  • ▸Sliding panels or modals
  • ▸Interactive hover and drag effects
  • ▸Smooth state transitions in React apps

Notable Features

  • ▸Spring-based animations for natural motion
  • ▸Declarative API integrated with React
  • ▸Interpolates multiple style values simultaneously
  • ▸Supports dynamic updates to animation targets
  • ▸Lightweight and composable

Origin & Creator

React Motion was created by Cheng Lou and open-sourced in 2015, becoming widely adopted for physics-based React animations.

Industrial Note

React Motion is used in web apps, dashboards, interactive UIs, and websites where smooth, physics-based motion improves user experience, such as sliding panels, accordions, loaders, and transitions.

More React-motion Typing Exercises

Simple React Motion AnimationVertical Slide AnimationOpacity Fade AnimationScale Up AnimationSpring Rotation AnimationBounce AnimationDelayed Start AnimationMulti-Direction AnimationOpacity and Position Combined

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher