2.2.15 • Published 5 months ago

use-scramble v2.2.15

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

useScramble

A lightweight (1KB), high performance, react-hook for random text animations.

The hook receives a set of parameteres that allows you to customize the pace, and style of the animation.

Development

  yarn dev

Will start the playground minisite at http://localhost:1234 and build the library on watch mode


Usage

Install to your react application

  npm install use-scramble

Import and call the useScramble hook

The hook returns a ref object, that you must apply to the target node, for the animation to take over.

import { useScramble } from 'use-scramble';

export const App = () => {
  const { ref } = useScramble({
    text: 'Achilles next, that nimble runner, swift on his feet as the wind',
    speed: 0.6,
    tick: 1,
    step: 1,
    scramble: 4,
    seed: 0,
  });

  return <p ref={ref} />;
};

Manual replay

Along with the ref, the hook returns a replay function, that you can call to start the animation manually.

You can also disable the first animation, by setting the playOnMount to false.

import { useScramble } from 'use-scramble';

export const App = () => {
  const { ref, replay } = useScramble({
    text: 'Achilles next, that nimble runner, swift on his feet as the wind',
    playOnMount: false
  });

  return <p ref={ref} onMouseOver={replay} onMouseOut={replay} />;
};

API Reference

Propertytypedefaultrangedescription
playOnMountbooleantrueSkip the animation on the first mount input
textstring-Set the text value of the animation. The animation, will start automatically.
speednumber10-1Internal clock framerate. 1 will tick 60 times a second. 0 will pause the animation
ticknumber11-∞Controls how many ticks pass for an animation redraw. Combined with speed, you can fully control the pace rate
stepnumber11-∞Controls the animation step. On every redraw, the algorithm moves forward, by step characters.
scramblenumber10-∞Controls how many times to randomize each character. A value of 0 will emulate a typewriter effect.
seednumber10-∞The seed, adds randomized characters ahead of the animation step, animating characters across the text block.
chancenumber10-1Chance of scrambling a character, range from 0 to 1, 0 being no chance, and 1 being 100% chance.
rangenumber[]65,125Unicode characters range to select random characters from
overdriveboolean, numbertrueDefaults to underscore (95) unicode character, or provide a custom unicode value
overflowbooleantrueOverflow, animates over the previous text, and when false resets the text contents, and restarts the animation from an empty string.
ignorestring[]" "Ignore specific characters when animating a string. By default only spaces are ignored, used to maintain the shape of the text.
onAnimationStartfunction-callback invoked when the animation starts playing
onAnimationFramefunction-callback invoked on every redraw
onAnimationEndfunction-callback invoked on when the animation ends

Return Values

Along with the ref the return value, contains a replay function, that you can invoke to restart the animation.

const { ref, replay } = useScramble({ text: 'your_text' });

return <p ref={ref} onclick={replay} />;

Reduced Motion

If the user has requested to minimize non-essential motion with prefers-reduced-motion:reduce, the animation is entirely disabled.

Unicode Values

GlyphUnicodeDescription
 32Space mark
!33Exclamation mark
"34Quotation mark
#35Hash
\$36Dollar sign
%37Percent sign
&38Ampersand
\'39Apostrophe
(40Left parenthesis
)41Right parenthesis
*42Asterisk
+43Plus sign
","44Comma
-45Hyphen-minus
.46Full stop
/47Slash (Solidus)
048Digit Zero
149Digit One
250Digit Two
351Digit Three
452Digit Four
553Digit Five
654Digit Six
755Digit Seven
856Digit Eight
957Digit Nine
:58Colon
;59Semicolon
<60Less-than sign
=61Equal sign
>62Greater-than sign
?63Question mark
@64At sign
A65Latin Capital letter A
B66Latin Capital letter B
C67Latin Capital letter C
D68Latin Capital letter D
E69Latin Capital letter E
F70Latin Capital letter F
G71Latin Capital letter G
H72Latin Capital letter H
I73Latin Capital letter I
J74Latin Capital letter J
K75Latin Capital letter K
L76Latin Capital letter L
M77Latin Capital letter M
N78Latin Capital letter N
O79Latin Capital letter O
P80Latin Capital letter P
Q81Latin Capital letter Q
R82Latin Capital letter R
S83Latin Capital letter S
T84Latin Capital letter T
U85Latin Capital letter U
V86Latin Capital letter V
W87Latin Capital letter W
X88Latin Capital letter X
Y89Latin Capital letter Y
Z90Latin Capital letter Z
[91Left Square Bracket
\ 92Backslash
]93Right Square Bracket
^94Circumflex accent
_95Low line
`96Grave accent
a97Latin Small Letter A
b98Latin Small Letter B
c99Latin Small Letter C
d100Latin Small Letter D
e101Latin Small Letter E
f102Latin Small Letter F
g103Latin Small Letter G
h104Latin Small Letter H
i105Latin Small Letter I
j106Latin Small Letter J
k107Latin Small Letter K
l108Latin Small Letter L
m109Latin Small Letter M
n110Latin Small Letter N
o111Latin Small Letter O
p112Latin Small Letter P
q113Latin Small Letter Q
r114Latin Small Letter R
s115Latin Small Letter S
t116Latin Small Letter T
u117Latin Small Letter U
v118Latin Small Letter V
w119Latin Small Letter W
x120Latin Small Letter X
y121Latin Small Letter Y
z122Latin Small Letter Z
{123Left Curly Bracket
|124Vertical bar
}125Right Curly Bracket
~126Tilde
2.2.15

5 months ago

2.2.13

5 months ago

2.2.14

5 months ago

2.2.13-beta.3

5 months ago

2.2.13-beta.0

5 months ago

2.2.13-beta.2

5 months ago

2.2.13-beta.1

5 months ago

2.2.12

1 year ago

2.2.11

1 year ago

2.2.10

1 year ago

2.2.9

1 year ago

2.2.8

1 year ago

2.2.7

1 year ago

2.2.6

1 year ago

2.2.5

1 year ago

2.2.4

1 year ago

2.2.3

1 year ago

2.2.2

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago

0.0.1

1 year ago