I have an About us web page and I need to animate this title:
I found this one, that uses anime.js
and jQuery
.
Here's my About.js:
import React from 'react';
import '../css/About.css'
import '../scripts/aboutAnimation'
import AboutInfo from "../components/AboutInfo";
const About = () => {
return (
<div className="containerAbout">
<div className="title-container">
<p className="title">About us...</p>
</div>
<div className="forest">
<AboutInfo
name="Vasiliy Pupkin"
number="+375 29 973 79 43"
email="[email protected]"
position="top"
/>
<AboutInfo
name="Aleksey Smirnov"
number="+375 29 337 91 07"
email="[email protected]"
position="middle"
/>
<AboutInfo
name="Ivan Karpovski"
number="+375 29 655 74 25"
email="[email protected]"
position="down"
/>
</div>
</div>
);
}
export default About;
Here's my aboutAnimation.js:
import anime from 'animejs/lib/anime.es.js';
let textWrapper = document.getElementsByClassName('title');
textWrapper.innerHTML = textWrapper.textContent.replace(/\S/g, "<span class='letter'>$&</span>");
anime.timeline({loop: true})
.add({
targets: '.title .letter',
translateX: [40,0],
translateZ: 0,
opacity: [0,1],
easing: "easeOutExpo",
duration: 1200,
delay: (el, i) => 500 + 30 * i
}).add({
targets: '.title .letter',
translateX: [0,-30],
opacity: [1,0],
easing: "easeInExpo",
duration: 1100,
delay: (el, i) => 100 + 30 * i
});
This is an error I get:
TypeError: Cannot read property 'replace' of undefined
I've deleted the 5th line and checked if textWrapper
exists through console.log()
command, and console shows something like this:
By the way: if I type those 2 lines in Chrome console, I get this:
You should use,
Because getElementsByClassName returns an array-like object of all child elements which have all of the given class names.
Try assigning some id to p tag and try using getElementById
Am Adding new Functional Component Solution! I think this might help you.