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
|
export class Circle {
leftConfig: CircleConfig;
rightConfig: CircleConfig;
centerX!: number;
centerY!: number;
constructor() {
this.leftConfig = {
wrapper: document.querySelector(".circle__text__wrapper__left") as HTMLElement,
items: document.querySelectorAll(".circle__text__left__item"),
radius: 0,
direction: 1,
};
this.rightConfig = {
wrapper: document.querySelector(".circle__text__wrapper__right") as HTMLElement,
items: document.querySelectorAll(".circle__text__right__item"),
radius: 0,
direction: -1,
};
this.updateDimensions();
this.init();
}
updateItemsPosition(config: CircleConfig, scrollY: number): void {
const { items, radius, direction } = config;
const totalItems = items.length;
const spacing = Math.PI / totalItems;
items.forEach((item, index) => {
const angle = index * spacing - scrollY * direction * Math.PI * 2;
const x = this.centerX + Math.cos(angle) * radius;
const y = this.centerY + Math.sin(angle) * radius;
const rotationOffset = direction === -1 ? 180 : 0;
const rotation = (angle * 180) / Math.PI + rotationOffset;
gsap.set(item, {
x,
y,
rotation,
transformOrigin: "center center",
});
});
}
createScrollAnimations(): void {
ScrollTrigger.create({
trigger: ".circle__wrapper",
start: "top bottom",
end: "bottom top",
scrub: 1,
onUpdate: (self) => {
const scrollY = self.progress * 0.5;
this.updateItemsPosition(this.leftConfig, scrollY);
this.updateItemsPosition(this.rightConfig, scrollY);
},
});
}
}
|