packages/docs/docs/transitions/presentations/swap.mdx
A presentation that swaps scenes with perspective, depth, and a floor reflection.
<Demo type="swap" />:::warning
This presentation is built with HTML-in-canvas and requires Google Chrome with chrome://flags/#canvas-draw-element enabled. It does not work in Firefox or Safari.
:::
import {AbsoluteFill} from 'remotion';
const Letter: React.FC<{
children: React.ReactNode;
color: string;
}> = ({children, color}) => {
return (
<AbsoluteFill
style={{
backgroundColor: color,
opacity: 0.9,
justifyContent: 'center',
alignItems: 'center',
fontSize: 200,
color: 'white',
}}
>
{children}
</AbsoluteFill>
);
};
// ---cut---
import {linearTiming, TransitionSeries} from '@remotion/transitions';
import {swap} from '@remotion/transitions/swap';
const BasicTransition = () => {
return (
<TransitionSeries>
<TransitionSeries.Sequence durationInFrames={40}>
<Letter color="#0b84f3">A</Letter>
</TransitionSeries.Sequence>
<TransitionSeries.Transition
presentation={swap({})}
timing={linearTiming({durationInFrames: 30})}
/>
<TransitionSeries.Sequence durationInFrames={60}>
<Letter color="pink">B</Letter>
</TransitionSeries.Sequence>
</TransitionSeries>
);
};
Accepts an object with the following options:
reflection?Controls the strength of the reflected scenes on the floor.
Defaults to 0.4.
perspective?Controls the perspective distortion while the scenes move.
Defaults to 0.2.
depth?Controls how far each scene moves into depth during the swap.
Defaults to 3.
<CompatibilityTable chrome firefox={false} safari={false} nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
For Preview, Chrome with the chrome://flags/#canvas-draw-element flag enabled is required.
The fragment shader is adapted from the swap GL Transition by gre, licensed under MIT.