Code Monkey home page Code Monkey logo

scramble's Introduction

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

Property type default description
as string - polymorphic tag
play boolean true start/stop animation
text string - text to scramble.
speed number 0.4 0-1 range that determines the ticking speed. 1 means 1 tick per frame
scramble number 8 how many times each character will randomize
step number 1 how many characters are added to the scramble on each tick
stepInterval number 1 how many ticks it requires to increment the step index
seed number 3 adds random characters to the scramble, ahead of the ticking loop
seedInterval number 10 ticks required to seed more random characters
onComplete function - 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's People

Contributors

tol-is avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

heydryft xyztlp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.