Animation Effects
Animation Effects
Add elegant animation effects to streaming rendered content, supporting progressive text display to enhance user reading experience.
Streaming animation effects are designed for real-time content rendering, using smooth transition animations to make content presentation more natural and avoid visual discomfort from abrupt content updates.
Parameter | Description | Type | Default |
---|---|---|---|
hasNextChunk | Whether there is more streaming data | boolean | false |
enableAnimation | Enable text fade-in animation | boolean | false |
animationConfig | Text animation configuration | AnimationConfig | { fadeDuration: 200, easing: 'ease-in-out' } |
Property | Description | Type | Default |
---|---|---|---|
fadeDuration | Fade animation duration in milliseconds | number | 200 |
easing | Animation easing function | string | 'ease-in-out' |
import { XMarkdown } from '@ant-design/x-markdown';const App = () => {return (<XMarkdowncontent="# Hello World\n\nThis is a streaming rendering example."streaming={{hasNextChunk: true,enableAnimation: true,animationConfig: {fadeDuration: 200,easing: 'ease-in-out',},}}/>);};
import { XMarkdown } from '@ant-design/x-markdown';const CustomAnimationExample = () => {return (<XMarkdowncontent="## Custom Animation Effects\n\nThis text will display with slower animation effects."streaming={{hasNextChunk: true,enableAnimation: true,animationConfig: {fadeDuration: 500, // Longer animation timeeasing: 'ease-out', // Different easing effect},}}/>);};
ease-in-out
: Smooth acceleration and deceleration (default)linear
: Constant speed animationease-in
: Ease-in effectease-out
: Ease-out effectAnimation effects trigger under the following conditions:
hasNextChunk
import { useState, useEffect } from 'react';import { XMarkdown } from '@ant-design/x-markdown';const CombinedStreamingExample = () => {const [content, setContent] = useState('');const [hasNextChunk, setHasNextChunk] = useState(true);useEffect(() => {const chunks = ['# Streaming Rendering and Animation','\n\nThis combines','**syntax processing** and','*animation effects* in','a complete example.',];let index = 0;const timer = setInterval(() => {if (index < chunks.length) {setContent((prev) => prev + chunks[index]);index++;if (index === chunks.length) {setHasNextChunk(false);}} else {clearInterval(timer);}}, 800);return () => clearInterval(timer);}, []);return (<XMarkdowncontent={content}streaming={{hasNextChunk,enableAnimation: true,animationConfig: {fadeDuration: 400,easing: 'ease-in-out',},incompleteMarkdownComponentMap: {link: 'loading-link',image: 'loading-image',},}}/>);};
Combined with animation effects, you can achieve a typewriter effect:
import { useState, useEffect } from 'react';import { XMarkdown } from '@ant-design/x-markdown';const TypewriterEffect = () => {const [content, setContent] = useState('');const [hasNextChunk, setHasNextChunk] = useState(true);const fullText ='# Typewriter Effect\n\nThis is an example simulating typewriter effect, with each character gradually appearing.';useEffect(() => {let index = 0;const timer = setInterval(() => {if (index <= fullText.length) {setContent(fullText.slice(0, index));index++;if (index > fullText.length) {setHasNextChunk(false);}} else {clearInterval(timer);}}, 50); // 50ms per characterreturn () => clearInterval(timer);}, []);return (<XMarkdowncontent={content}streaming={{hasNextChunk,enableAnimation: true,animationConfig: {fadeDuration: 100, // Quick fade-ineasing: 'linear',},}}/>);};
Animation Duration Selection:
Easing Function Selection:
ease-in-out
ease-out
linear
Avoid Excessive Animation:
A: Please check the following conditions:
enableAnimation
is set to true
hasNextChunk
is correctly controlledA: Recommended optimizations:
fadeDuration
timelinear
easing functionA: Can be controlled through custom components:
const NoAnimationComponent = ({ children }) => {return <div style={{ animation: 'none' }}>{children}</div>;};<XMarkdown components={{ p: NoAnimationComponent }} streaming={{ enableAnimation: true }} />;