It provides a clean, chainable API to build complex text-based animations sequentially without messy callbacks or complex state management.
1. Install TypeFX.js package with NPM and import it into your project.
# NPM $ npm install typefxjs
import TypeFX from "typefxjs";
2. For a quick setup, use the CDN link. Just add this script tag to your HTML file:
<script src="https://cdn.jsdelivr.net/npm/typefxjs/dist/typefx.umd.min.js"></script>
3. Create an HTML element to serve as the container for the text animation.
<p id="example"></p>
4. Create a new instance of TypeFX and pass the target element to the constructor. From there, you can chain methods to build your animation sequence. The example here types a sentence, waits, moves the cursor back, selects a word, deletes it, and types a new phrase.
const element = document.querySelector('#example');
new TypeFX(element)
.type("This is a demo of TypeFX.js.")
.wait(500)
.move(-11)
.wait(300)
.select(10)
.wait(400)
.delete()
.type("a typewriter effect!"); 5. Pass an options object as the second argument to the constructor to customize the behavior:
new TypeFX(element,{
speed: 50,
speedRange: 50,
caretWidth: "0.05em"
}) 6. All chainable API methods.
Text Operations:
Cursor Control:
Timing and Flow:
7. Integrate it with Vue 3’s composition API:
<template>
<p ref="content"></p>
</template>
<script setup>
import { onMounted, useTemplateRef } from 'vue';
import TypeFX from 'typefxjs';
const contentEl = useTemplateRef('content');
onMounted(() => {
new TypeFX(contentEl.value)
.type("Vue 3 integration example")
.wait(500)
.move(-8)
.select(8)
.delete()
.type("demonstration");
});
</script> Q: Can I use HTML tags inside the strings I type?
A: Based on the source code, the .type() method creates text nodes for each character. It doesn’t parse HTML strings.
Q: How do I create a looping animation?
A: The library doesn’t have a built-in .loop() method. However, you can create a loop by wrapping your animation sequence in a function and calling it recursively within a .then() callback at the end of the chain.
Q: What happens if the target element already contains text?
A: TypeFX.js will append its caret to the end of the existing content and start its operations from there. It doesn’t automatically clear the element on initialization. If you want to start with a clean slate, you should either ensure the HTML element is empty or call .quickClear() at the beginning of your chain.
Q: How does TypeFX.js perform with very long text sequences?
A: The library creates individual DOM elements for each character, so performance may degrade with extremely long text (thousands of characters). For large content blocks, consider breaking text into smaller chunks or using the quickClear() method to reset content between sequences.
Q: Can multiple TypeFX instances run simultaneously on the same page?
A: Yes, TypeFX.js supports multiple concurrent instances on different elements. Each instance maintains its own queue and styling, so multiple typewriter effects can run independently without interference.
Q: How do I handle user interactions while TypeFX animations are running?
A: TypeFX.js provides the cancel() method to stop queued operations immediately. You can call this method in response to user clicks or other interactions, then optionally start new sequences based on the user action.
The post Advanced Typewriter Animation Library – TypeFX.js appeared first on CSS Script.
If you're a Windows user who's looking for a PC version of the Apple Mac…
FORT WAYNE, Ind. (WOWO) — The state of Indiana has agreed to let the Indiana…
FORT WAYNE, Ind. (WOWO) — Severe thunderstorms are expected to move across central Indiana in…
Universal Pictures and Focus Features have taken the stage at CinemaCon. We're expecting new looks…
Maritza Montejo, a Liberty Tax Service office manager, helps Aurora Hernandez, left, with her taxes…
The Rockford Education Association is accusing Rockford Public Schools 205 of unfair labor practices. The…
This website uses cookies.