Skip to content

Commit

Permalink
add: footer glitch effect
Browse files Browse the repository at this point in the history
  • Loading branch information
ppmpreetham committed Jan 4, 2025
1 parent a6d2913 commit 3beb0c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function Footer() {
</div>
<div className="line w-full my-4"></div>
<p className="text-big-phone-xl font-calcio text-white responsive-text lg:text-big-desktop-xl">
<AnimatedText text="ENIGMA" />
<AnimatedText text="ENIGMA" time={2} customText='▂▄▆█' preStyle='text-enigma-green'/>
</p>
</footer>
);
Expand Down
13 changes: 9 additions & 4 deletions src/components/text.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import React, { useState, useRef } from 'react';

const AnimatedText = ({ text, className = '', customText = '' }) => {
const AnimatedText = ({ text, className = '', customText = '', time = 1, preStyle = '' }) => {
const [animatedTitle, setAnimatedTitle] = useState(text || '');
const intervalRef = useRef(null);
const [isHovered, setIsHovered] = useState(false);

const finalClass = isHovered ? preStyle : className;

// Emojis work too :))
const letters = customText === '' ? 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' : customText;

const handleMouseOver = () => {
let iteration = 0;
setIsHovered(true);

function animateText() {
intervalRef.current = setInterval(() => {
Expand All @@ -20,10 +24,10 @@ const AnimatedText = ({ text, className = '', customText = '' }) => {
: letters[Math.floor(Math.random() * letters.length)];
})
.join('');

setAnimatedTitle(randomText);

iteration += 0.5;
iteration += 0.5/time;

if (iteration >= text.length) {
clearInterval(intervalRef.current);
Expand All @@ -36,13 +40,14 @@ const AnimatedText = ({ text, className = '', customText = '' }) => {
};

const handleMouseOut = () => {
setIsHovered(false);
clearInterval(intervalRef.current);
setAnimatedTitle(text);
};

return (
<div>
<p className={`${className} inline`} onMouseOver={handleMouseOver} onMouseOut={handleMouseOut}>
<p className={`${finalClass} inline`} onMouseOver={handleMouseOver} onMouseOut={handleMouseOut}>
{animatedTitle}
</p>
</div>
Expand Down

0 comments on commit 3beb0c3

Please sign in to comment.