-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtext.js
80 lines (74 loc) · 2.26 KB
/
text.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Intersetion Observer
const IO = (item, options) => {
return new Promise((resolve) => {
const observer = new window.IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
resolve();
}
});
}, options);
observer.observe(item);
});
};
const p = document.querySelectorAll("[data-animation='paragraph']");
const H = document.querySelectorAll("[data-animation='heading']");
p.forEach((item) => {
const line = Splitting({
target: item,
by: "lines",
});
line.forEach((splitResult) => {
const wrappedLines = splitResult.words
.map(
(wordsArr) => `
<span class="word_wrap">
${wordsArr.outerHTML}
</span>`
)
.join("");
splitResult.el.innerHTML = wrappedLines;
});
gsap.set(item.querySelectorAll(".word"), {
yPercent: 100,
opacity: 0,
rotateX: 50,
transformStyle: "preserve-3d",
});
IO(item, { threshold: 0.8 }).then(() => {
const elem = item.querySelectorAll(".word");
gsap.to(elem, {
yPercent: 0,
opacity: 1,
rotateX: 0,
stagger: elem.length > 100 ? 0.02 : 0.03,
duration: elem.length > 100 ? 0.65 : 0.75,
ease: "easeOut",
// ease: "back.out(1.7)"
});
});
});
H.forEach((item) => {
Splitting({
target: item,
by: "chars",
});
gsap.set(item.querySelectorAll(".char"), {
opacity: 0,
yPercent: 100,
transformStyle: "preserve-3d",
});
IO(item, {
threshold: 1,
}).then(() => {
const elem = item.querySelectorAll(".char");
gsap.to(elem, {
opacity: 1,
yPercent: 0,
stagger: elem.length > 100 ? 0.02 : 0.03,
duration: elem.length > 100 ? 0.5 : 0.6,
// ease: "easeOut",
ease: "back.out(1.7)"
});
});
});