forked from cristinalare/supermodular.xyz
-
Notifications
You must be signed in to change notification settings - Fork 2
/
animations.js
68 lines (63 loc) · 1.47 KB
/
animations.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
// image sequence
gsap.registerPlugin(ScrollTrigger);
const canvas = document.getElementById("hero");
const context = canvas.getContext("2d");
const section = document.querySelector(".img-sequence-container");
const frameCount = 9;
const currentFrame = index => `./images/img-sequence/${index}.png`;
canvas.width = 329;
canvas.height = 329;
const images = [];
const unis = {
frame: 0
};
for (let i = 0; i < frameCount; i++) {
const img = new Image();
img.src = currentFrame(i);
images.push(img);
}
gsap.to(unis, {
frame: 9 - 1,
snap: "frame",
ease: "none",
// duration: 1,
scrollTrigger: {
trigger: section,
fastScrollEnd: true,
pin: true,
start: -5,
scrub: 0.3,
end: "+=200%"
},
onUpdate: render
});
images[0].onload = render;
function render() {
context.clearRect(0, 0, canvas.width, canvas.height);
context.drawImage(images[unis.frame], 0, 0, 329, 329);
}
// projects transition
const projects = gsap.utils.toArray('.project-card');
projects.forEach(project => {
gsap.from(project, {
opacity: 0,
scale: 0.5,
duration: 1,
scrollTrigger: {
trigger: project,
toggleActions: 'restart none none reverse',
}
});
});
const projectsDescriptions = gsap.utils.toArray('.project-description');
projectsDescriptions.forEach(description => {
gsap.from(description, {
opacity: 0,
y: 30,
duration: 1,
scrollTrigger: {
trigger: description,
toggleActions: 'restart none none reverse',
}
});
});