A tool for creating typewriter effect, with a simple, promise based api.
Install npm package
npm install text-typing
yarn add text-typing
And then import the package
import {textTyping} from "text-typing";
All you need to do is to initialize the tool, passing a reference to an existing DOM element, and start typing!
<h1 id="myHeading"></h1>
(async () => {
const txt = textTyping(document.getElementById("myHeading"));
await txt.typeText("Hello");
})();
You can call multiple methods on the same instance, either by using await
(inside an async
function), or by using then
after a method call
(async () => {
const txt = textTyping(elem);
await txt.typeText("Hello");
await txt.backspace(2);
})();
(() => {
const txt = textTyping(elem);
txt.typeText("Hello").then(resp => {
resp.backspace(2);
});
})();
The typing speed that is going to be used by called methods, if no specific speed is provided to the specific method.
If provided with a single number, the speed is going to be constant. An array of two numbers can be provided as the minimum (first number) and the maximum (second number) speed. In case of an array provided, the speed is going to be random in the specified range.
type <number> | <number[]>
optional true
default [100, 500]
The cursor that is going to be displayed.
type <string>
optional true
default |
Start typing the specified text in the given speed (if speed is not provided, the options speed will be used)
txt.typeText(text[, className][, speed])
<string>
: The text to be typed<string>
: An optional class or set of classes to be applied (If you want to add multiple classes, separate them with space)<number> | <number[]>
: The typing speedPromise
Insert a line break
txt.lineBreak()
none
Promise
Insert HTML element
txt.injectHTML(htmlElement[, speed])
<HTMLElement>
: The HTML element to be injected<number> | <number[]>
: The delay of the element injectionPromise
Delete the specified amount of letters from the begining of the text
txt.delete(iterations[, speed])
<number>
: The amount of letters to be deleted<number> | <number[]>
: The deletion speedPromise
Remove the specified amount of letters, starting from the end of the text
txt.backspace(iterations[, speed])
<number>
: The amount of letters to be removed<number> | <number[]>
: The deletion speedPromise
Place the cursor either at the begining or at the end of the text
txt.moveCursor(point)
<string>
: The point at which the cursor will be placed. Possible values: start
/ end
(If any value other than start
is provided, the cursor will be moved at the end of the text)Promise
Stop the execution for the given time
txt.sleep(speed)
<number> | <number[]>
: The time of pause in millisecondsPromise
Checkout the CHANGELOG file