-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
78 lines (67 loc) · 1.67 KB
/
Copy pathscript.js
File metadata and controls
78 lines (67 loc) · 1.67 KB
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
gsap.registerPlugin(ScrollTrigger);
let revealAnimations = [];
// Scroll
const lenis = new Lenis({
lerp: 0.07
});
lenis.on('scroll', ScrollTrigger.update)
gsap.ticker.add((time)=>{
lenis.raf(time * 1000)
})
// Reveal
document.querySelectorAll('.reveal').forEach(text => {
// Split text
let splitText = new SplitType(text, {
type: 'words'
})
// Animation
const section = text.closest('section');
gsap.from(splitText.words, {
opacity: 0,
ease: 'none',
stagger: 1,
duration: 2, // Adjust this value to make the animation faster
scrollTrigger: {
trigger: section,
start: 'top top',
end: () => `+=${window.innerHeight * 3}px`,
scrub: true,
// markers: true,
pin: true,
}
})
})
// Reveal animation
const setTextRevealAnimations = () => {
document.querySelectorAll('.text-reveal').forEach(text => {
// Split text
let splitText = new SplitType(text);
splitText.lines.forEach(line => {
const lineWrapper = document.createElement('div');
lineWrapper.classList.add('line-wrapper');
text.insertAdjacentElement('beforeEnd', lineWrapper);
lineWrapper.appendChild(line);
})
// Animation
const section = text.closest('section');
gsap.to(splitText.lines, {
y: 0,
ease: "power1.inOut",
stagger: .15,
scrollTrigger: {
trigger: text,
start: 'top bottom',
// markers: true,
toggleActions: 'play reset play reset'
}
})
});
}
setTextRevealAnimations();
// Handle resize
const resizeObserver = new ResizeObserver(
debounce(([entry]) => {
setTextRevealAnimations();
}, 500)
)
resizeObserver.observe(document.body)