Skip to content

Commit 211cafe

Browse files
committed
CaptureText-cdn-test
1 parent d012d3e commit 211cafe

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

cdns/CaptureText.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,45 @@
1-
class CaptureText{constructor(e,t,s=.7){this.textArray=e,this.selectors=t,this.speed=s,this.currentWordIndex=0,this.elements=document.querySelectorAll(this.selectors)}animateText(e){e.innerHTML=this.textArray[this.currentWordIndex].replace(/\S/g,"<span class='inline-block'>$&</span>"),anime.timeline({loop:!1}).add({targets:".animated-text .inline-block",scale:[4,1],opacity:[0,1],translateZ:0,easing:"easeOutExpo",duration:950/this.speed,delay:(e,t)=>70/this.speed*t}).add({targets:".animated-text .inline-block",opacity:0,duration:1e3,easing:"easeOutExpo",delay:1e3})}start(){let e=()=>{this.elements.forEach(e=>{this.animateText(e)}),this.currentWordIndex=(this.currentWordIndex+1)%this.textArray.length};e(),setInterval(()=>{e()},2750/this.speed)}}window.CaptureText=CaptureText;
1+
class CaptureText {
2+
constructor(textArray, speed = 0.7) {
3+
this.textArray = textArray;
4+
this.speed = speed;
5+
this.currentWordIndex = 0;
6+
this.textElements = document.querySelectorAll('.CaptureText');
7+
this.startTextAnimation();
8+
}
9+
10+
animateText(element) {
11+
if (element) {
12+
element.innerHTML = this.textArray[this.currentWordIndex].replace(
13+
/\S/g,
14+
"<span style='display: inline-block;'>$&</span>"
15+
);
16+
17+
anime.timeline({ loop: false })
18+
.add({
19+
targets: `.${element.className} span`,
20+
scale: [4, 1],
21+
opacity: [0, 1],
22+
translateZ: 0,
23+
easing: "easeOutExpo",
24+
duration: 950 / this.speed,
25+
delay: (el, i) => (70 / this.speed) * i,
26+
})
27+
.add({
28+
targets: `.${element.className} span`,
29+
opacity: 0,
30+
duration: 1000,
31+
easing: "easeOutExpo",
32+
delay: 1000,
33+
});
34+
}
35+
}
36+
37+
startTextAnimation() {
38+
this.textElements.forEach(element => this.animateText(element));
39+
setInterval(() => {
40+
this.currentWordIndex = (this.currentWordIndex + 1) % this.textArray.length;
41+
this.textElements.forEach(element => this.animateText(element));
42+
}, 2750 / this.speed);
43+
}
44+
}
45+

0 commit comments

Comments
 (0)