Skip to content

Commit 0f0b78d

Browse files
committed
dancedualtex-cdn-test
1 parent ad90a44 commit 0f0b78d

File tree

3 files changed

+74
-46
lines changed

3 files changed

+74
-46
lines changed

cdns/capturetext@animatio.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

cdns/capturetext@animatio2.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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.loadAnimeJS().then(() => this.startTextAnimation());
8+
}
9+
10+
loadAnimeJS() {
11+
return new Promise((resolve, reject) => {
12+
if (typeof anime !== 'undefined') {
13+
resolve();
14+
} else {
15+
const script = document.createElement('script');
16+
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js';
17+
script.onload = resolve;
18+
script.onerror = reject;
19+
document.head.appendChild(script);
20+
}
21+
});
22+
}
23+
24+
animateText(element) {
25+
if (element) {
26+
element.innerHTML = this.textArray[this.currentWordIndex].replace(
27+
/\S/g,
28+
"<span style='display: inline-block;'>$&</span>"
29+
);
30+
31+
anime.timeline({ loop: false })
32+
.add({
33+
targets: `.${element.className} span`,
34+
scale: [4, 1],
35+
opacity: [0, 1],
36+
translateZ: 0,
37+
easing: "easeOutExpo",
38+
duration: 950 / this.speed,
39+
delay: (el, i) => (70 / this.speed) * i,
40+
})
41+
.add({
42+
targets: `.${element.className} span`,
43+
opacity: 0,
44+
duration: 1000,
45+
easing: "easeOutExpo",
46+
delay: 1000,
47+
});
48+
}
49+
}
50+
51+
startTextAnimation() {
52+
this.textElements.forEach(element => this.animateText(element));
53+
setInterval(() => {
54+
this.currentWordIndex = (this.currentWordIndex + 1) % this.textArray.length;
55+
this.textElements.forEach(element => this.animateText(element));
56+
}, 2750 / this.speed);
57+
}
58+
}
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@ class DanceDualText {
55
this.direction = direction;
66
this.currentIndex = 0;
77
this.textElements = document.querySelectorAll('.DanceDualText');
8-
this.startTextAnimation();
8+
this.loadAnimeJS().then(() => this.startTextAnimation());
9+
}
10+
11+
loadAnimeJS() {
12+
return new Promise((resolve, reject) => {
13+
if (typeof anime !== 'undefined') {
14+
resolve();
15+
} else {
16+
const script = document.createElement('script');
17+
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js';
18+
script.onload = resolve;
19+
script.onerror = reject;
20+
document.head.appendChild(script);
21+
}
22+
});
923
}
1024

1125
animateText(element) {
@@ -58,4 +72,5 @@ class DanceDualText {
5872
}, 3000 / this.speed);
5973
}
6074
}
75+
6176

0 commit comments

Comments
 (0)