From e62d7258f6524b1d86088f2ecbb2357c7501aced Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Thu, 23 Mar 2023 17:59:44 +0800 Subject: [PATCH] opacity effect --- src/VerticalText.tsx | 54 +++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/src/VerticalText.tsx b/src/VerticalText.tsx index a3d27fb..253a3a9 100644 --- a/src/VerticalText.tsx +++ b/src/VerticalText.tsx @@ -28,12 +28,23 @@ const VerticalText: React.FC = ({ }) => { const current = useCurrentFrame(); const textArray = Array.from(text); - const currentEndIndex = ~~( - (textArray.length * (current - from)) / - (to - from) + const currentEndIndex = interpolate( + current, + [from, to], + [0, textArray.length] + ); + const r = random(current - (current % 3)); + const duration = to - from; + const opacities = textArray.map((_, i) => + interpolate( + current, + [ + from + (i * duration) / textArray.length, + from + ((i + 1) * duration) / textArray.length, + ], + [0, 1] + ) ); - const r = random(current - (current % 2)); - const opacity = interpolate(current, [from, from + 8], [0, 1]); return ( = ({ from={from} durationInFrames={disappear ? disappear - from : 4096} style={{ - opacity, top: `${1080 - y}px`, left: x, - letterSpacing: '0.2em', - display: 'flex', - flexDirection: 'column', - justifyContent: 'flex-end', width: 'min-content', - fontSize: `${fontSize}px`, + height: 'min-content', + display: 'flex', + flexDirection: 'row', writingMode: 'vertical-lr', + fontSize: `${fontSize}px`, overflow: 'hidden', }} > - {textArray.slice(0, currentEndIndex).join('')} - {currentEndIndex < text.length && textArray[~~(r * textArray.length)]} + {textArray.slice(0, currentEndIndex).map((char, index) => ( +
+ {char} +
+ ))} + {currentEndIndex < textArray.length && ( +
+ {textArray[~~(r * textArray.length)]} +
+ )}
);