-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
62 lines (54 loc) · 1.58 KB
/
script.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
gsap.registerPlugin(ScrollTrigger);
const additionalY = { val: 0 };
let additionalYAnim;
let offset = 0;
const cols = gsap.utils.toArray(".col");
cols.forEach((col, i) => {
const images = col.childNodes;
// DUPLICATE IMAGES FOR LOOP
images.forEach((image) => {
var clone = image.cloneNode(true);
col.appendChild(clone);
});
// SET ANIMATION
images.forEach((item) => {
let columnHeight = item.parentElement.clientHeight;
let direction = i % 2 !== 0 ? "+=" : "-="; // Change direction for odd columns
gsap.to(item, {
y: direction + Number(columnHeight / 2),
duration: 20,
repeat: -1,
// ease: "none",
modifiers: {
y: gsap.utils.unitize((y) => {
if (direction == "+=") {
offset += additionalY.val;
y = (parseFloat(y) - offset) % (columnHeight * 0.5);
} else {
offset += additionalY.val;
y = (parseFloat(y) + offset) % -Number(columnHeight * 0.5);
}
return y;
})
}
});
});
});
const imagesScrollerTrigger = ScrollTrigger.create({
trigger: "section",
start: "top 50%",
end: "bottom 50%",
onUpdate: function (self) {
const velocity = self.getVelocity();
if (velocity > 0) {
if (additionalYAnim) additionalYAnim.kill();
additionalY.val = -velocity / 2000;
additionalYAnim = gsap.to(additionalY, { val: 0 });
}
if (velocity < 0) {
if (additionalYAnim) additionalYAnim.kill();
additionalY.val = -velocity / 3000;
additionalYAnim = gsap.to(additionalY, { val: 0 });
}
}
});