Skip to content

Commit ad90a44

Browse files
committed
dancedualtex-cdn-test
1 parent 79d0130 commit ad90a44

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

cdns/dancedualtext@animatio.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
class DanceDualText {
2+
constructor(textArray, speed = 0.7, direction = 'none') {
3+
this.textArray = textArray;
4+
this.speed = speed;
5+
this.direction = direction;
6+
this.currentIndex = 0;
7+
this.textElements = document.querySelectorAll('.DanceDualText');
8+
this.startTextAnimation();
9+
}
10+
11+
animateText(element) {
12+
if (element) {
13+
const currentText = this.textArray[this.currentIndex];
14+
element.innerHTML = currentText.replace(/\S/g, "<span style='display: inline-block; opacity: 0;'>$&</span>");
15+
16+
let translateYStart, translateYEnd;
17+
18+
switch (this.direction) {
19+
case "top":
20+
translateYStart = 20;
21+
translateYEnd = -20;
22+
break;
23+
case "bottom":
24+
translateYStart = -20;
25+
translateYEnd = 20;
26+
break;
27+
default:
28+
translateYStart = 20;
29+
translateYEnd = -20;
30+
}
31+
32+
anime.timeline({ loop: false })
33+
.add({
34+
targets: element.children,
35+
opacity: [0, 1],
36+
translateY: [translateYStart, 0],
37+
translateZ: 0,
38+
duration: 1000,
39+
delay: (el, i) => 50 * i,
40+
easing: 'easeOutExpo',
41+
})
42+
.add({
43+
targets: element.children,
44+
opacity: 0,
45+
translateY: [0, translateYEnd],
46+
duration: 1000,
47+
delay: (el, i) => 50 * i,
48+
easing: 'easeInExpo',
49+
}, '+=1000');
50+
}
51+
}
52+
53+
startTextAnimation() {
54+
this.textElements.forEach(element => this.animateText(element));
55+
setInterval(() => {
56+
this.currentIndex = (this.currentIndex + 1) % this.textArray.length;
57+
this.textElements.forEach(element => this.animateText(element));
58+
}, 3000 / this.speed);
59+
}
60+
}
61+

0 commit comments

Comments
 (0)