DEV Community

Cover image for Obfuscate & Reveal text animation in React using baffle.js
Hosenur Rahaman
Hosenur Rahaman

Posted on

 

Obfuscate & Reveal text animation in React using baffle.js

We are going to recreate this baffle

Lets get started

First we will install baffle.js package by running the following command.

npm install --save baffle
Enter fullscreen mode Exit fullscreen mode

Import baffle

import baffle from 'baffle';
Enter fullscreen mode Exit fullscreen mode

Assign a specific className to the div which contains the text you want to apply the obfuscated effect.
Here is an example:
In this case we have assigned the class 'obfuscated' to the div.

<div className = "col obfuscated">
        tothemoon.
</div>
Enter fullscreen mode Exit fullscreen mode

Use useEffect hook to start the animation.

useEffect(() => {
        const target = baffle('.obfuscated')
        target.set({
            characters: "█▓█ ▒░/▒░ █░▒▓/ █▒▒ ▓▒▓/█<░▒ ▓/░>",
            speed: 100
        })
        target.start()
        target.reveal(1000, 100)
    })
Enter fullscreen mode Exit fullscreen mode

Replace your div class accordingly in this line.

const target = baffle('.obfuscated')
Enter fullscreen mode Exit fullscreen mode

Set your animation duration and delay accordingly in the last line

target.reveal(duration, delay)
Enter fullscreen mode Exit fullscreen mode

Now you are all set, and the effect should take place as soon as the page loads.

Top comments (0)

Top Posts from the React Ecosystem

1. Changes In The Official React Documentation

The former React Docs Beta has been officially released as the updated React documentation at react.dev after years of hard work and refinement. Check out the brand new React Docs: What’s New in the Updated React Docs

2. CRA's Time is Over

React developer team has removed create-react-app (CRA) from official documentation rendering it no longer the default setup method for new projects. The bulky setup, slow, and outdated nature of CRA led to its removal: create-react-app is officially dead

3. How to Fetch Dev.to Articles for Your Portfolio

Integrate the articles of your Dev.to profile into your personal portfolio with either React, Vue, or Next.js by following these simple steps. It outlines how to include frontend to pull the information and correctly utilizes the Dev.to API: How to Fetch Your Dev.to Articles for Your Portfolio with React