@a7sc11u/scramble 中文文档教程

发布于 4年前 浏览 19 更新于 3年前

Scramble

一个用于 React 的乱序文本 UI 组件。

动画维护一个内部滴答时钟,每秒运行多达 60 次,或每个动画帧运行一次。 动画从文本的开头开始,直到输入结束,给定一组参数,这些参数允许您控制添加的字符数和滴答数,以及每个字符随机化的次数。

https://scramble.vercel.app/ 现场演示

Props

Propertytypedefaultdescription
asstring-polymorphic tag
playbooleantruestart/stop animation
textstring-text to scramble.
speednumber0.40-1 range that determines the ticking speed. 1 means 1 tick per frame
scramblenumber8how many times each character will randomize
stepnumber1how many characters are added to the scramble on each tick
stepIntervalnumber1how many ticks it requires to increment the step index
seednumber3adds random characters to the scramble, ahead of the ticking loop
seedIntervalnumber10ticks required to seed more random characters
onCompletefunction-callback invoked on completion

Installation

  yarn add @a7sc11u/scramble
  //or
  npm install @a7sc11u/scramble

Usage

import { TextScramble } from '@a7sc11u/scramble';

export const App = () => {

  const elRef = React.useRef<HTMLDivElement>(null);

  const handleComplete = () => {
    console.log('scramble is done');
  }

  return (
    <TextScramble 
      ref={elRef}
      as="div"
      play={true}
      speed={0.4}
      scramble={8}
      step={1}
      stepInterval={1}
      seed={3}
      seedInterval={10}
      onComplete={handleComplete}
      text="Fugiat ullamco non magna dolor excepteur." 
    />
  );
};

Scramble

A scramble text UI component for react.

The animation maintains an internal ticking clock, that runs up to 60 times per second, or once per animation frame. The animation starts from the beginning of the text, and scrambles until the end of the input, given a set of parameters that allow you to control how many characters are added and over how many ticks, and how many times each character is randomized.

Live demo at https://scramble.vercel.app/

Props

Propertytypedefaultdescription
asstring-polymorphic tag
playbooleantruestart/stop animation
textstring-text to scramble.
speednumber0.40-1 range that determines the ticking speed. 1 means 1 tick per frame
scramblenumber8how many times each character will randomize
stepnumber1how many characters are added to the scramble on each tick
stepIntervalnumber1how many ticks it requires to increment the step index
seednumber3adds random characters to the scramble, ahead of the ticking loop
seedIntervalnumber10ticks required to seed more random characters
onCompletefunction-callback invoked on completion

Installation

  yarn add @a7sc11u/scramble
  //or
  npm install @a7sc11u/scramble

Usage

import { TextScramble } from '@a7sc11u/scramble';

export const App = () => {

  const elRef = React.useRef<HTMLDivElement>(null);

  const handleComplete = () => {
    console.log('scramble is done');
  }

  return (
    <TextScramble 
      ref={elRef}
      as="div"
      play={true}
      speed={0.4}
      scramble={8}
      step={1}
      stepInterval={1}
      seed={3}
      seedInterval={10}
      onComplete={handleComplete}
      text="Fugiat ullamco non magna dolor excepteur." 
    />
  );
};
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文