-
Notifications
You must be signed in to change notification settings - Fork 41
/
app.js
59 lines (49 loc) · 1.09 KB
/
app.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
const canvas = document.querySelector(".canvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const context = canvas.getContext("2d");
const frameCount = 179;
const currentFrame = (index) => `./best-ball/${(index + 1).toString()}.jpg`;
const images = [];
let ball = { frame: 0 };
for (let i = 0; i < frameCount; i++) {
const img = new Image();
img.src = currentFrame(i);
console.log(currentFrame(i));
images.push(img);
}
gsap.to(ball, {
frame: frameCount - 1,
snap: "frame",
ease: "none",
scrollTrigger: {
scrub: 0.5,
pin: "canvas",
end: "500%",
},
onUpdate: render,
});
gsap.fromTo(
".ball-text",
{
opacity: 0,
},
{
opacity: 1,
scrollTrigger: {
scrub: 1,
start: "50%",
end: "60%",
},
onComplete: () => {
gsap.to(".ball-text", { opacity: 0 });
},
}
);
images[0].onload = render;
function render() {
context.canvas.width = images[0].width;
context.canvas.height = images[0].height;
context.clearRect(0, 0, canvas.width, canvas.height);
context.drawImage(images[ball.frame], 0, 0);
}