Download script.js from LudOkapi/diagonal-scroll-delight: direct link, hf CLI and curl.
- Browser
- Download file 2.03 kB
-
https://huggingface.co/spaces/LudOkapi/diagonal-scroll-delight/resolve/main/script.js
- Command line
-
hf download hf://spaces/LudOkapi/diagonal-scroll-delight/script.js
-
curl -L -o script.js https://huggingface.co/spaces/LudOkapi/diagonal-scroll-delight/resolve/main/script.js
2.03 kB
| 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' | |
| }); | |
| }); | |
| }); | |