File size: 2,026 Bytes
833b632
ac2ecb5
 
 
 
 
 
 
 
 
 
 
 
 
833b632
 
 
 
 
 
 
 
 
 
 
 
 
ac2ecb5
 
833b632
 
ac2ecb5
 
 
 
 
 
 
833b632
 
ac2ecb5
 
 
833b632
 
 
 
 
 
 
 
 
ac2ecb5
 
 
 
 
 
 
 
833b632
ac2ecb5
 
 
 
 
 
833b632
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

document.addEventListener('DOMContentLoaded', () => {
    // Initialize GSAP and ScrollTrigger
    gsap.registerPlugin(ScrollTrigger);

    // Get the elements
    const container = document.getElementById('diagonal-scroll-container');
    const contentWrapper = document.getElementById('content-wrapper');
    const panels = gsap.utils.toArray('.panel');

    // Calculate total width and height of all panels
    const totalWidth = window.innerWidth * panels.length;
    const totalHeight = window.innerHeight * panels.length;

    // Set initial styles for diagonal layout
    gsap.set(contentWrapper, {
        position: 'absolute',
        top: '50%',
        left: '50%',
        width: totalWidth,
        height: totalHeight,
        xPercent: -50,
        yPercent: -50,
        rotation: 45,
        transformOrigin: 'center center'
    });

    // Set up the diagonal scroll effect
    gsap.to(contentWrapper, {
        xPercent: -50 + (panels.length * 50),
        yPercent: -50 - (panels.length * 50),
        ease: 'none',
        scrollTrigger: {
            trigger: container,
            start: 'top top',
            end: () => `+=${Math.sqrt(totalWidth * totalWidth + totalHeight * totalHeight)}`,
            scrub: 1,
            pin: true,
            anticipatePin: 1,
            invalidateOnRefresh: true
        }
    });

    // Position each panel correctly
    panels.forEach((panel, i) => {
        gsap.set(panel, {
            position: 'absolute',
            left: i * window.innerWidth,
            top: 0,
            width: '100vw',
            height: '100vh'
        });
    });

    // Handle resize events
    window.addEventListener('resize', () => {
        ScrollTrigger.refresh();
    });

    // Smooth scroll to next panel on arrow click
    document.querySelector('.animate-bounce')?.addEventListener('click', () => {
        gsap.to(window, {
            scrollTo: window.innerHeight * 0.8,
            duration: 1.5,
            ease: 'power2.inOut'
        });
    });
});