Created
January 6, 2026 05:52
-
-
Save SakuraRinDev/67cc7b0db9799112ef175793f2fc9718 to your computer and use it in GitHub Desktop.
Rolling text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="container"> | |
| <div class="tube"> | |
| <h1 class="line line1">SplitText</h1> | |
| <h1 class="line line2">SplitText</h1> | |
| <h1 class="line line3">SplitText</h1> | |
| <h1 class="line line3">SplitText</h1> | |
| </div> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // original - https://codepen.io/petebarr/pen/oJvVpw | |
| gsap.registerPlugin(SplitText); | |
| console.clear(); | |
| // Make container visible | |
| const container = document.querySelector(".container"); | |
| gsap.set(container, { visibility: "visible" }); | |
| // Grab all lines | |
| const lines = document.querySelectorAll(".line"); | |
| // Split characters for all lines | |
| const splitLines = Array.from(lines).map(line => | |
| new SplitText(line, { type: "chars", charsClass: "char" }) | |
| ); | |
| // 3D setup | |
| const width = window.innerWidth; | |
| const height = window.innerHeight; | |
| const depth = -width / 8; | |
| const transformOrigin = `50% 50% ${depth}`; | |
| gsap.set(lines, { perspective: 700, transformStyle: "preserve-3d" }); | |
| // Timeline animation | |
| const animTime = 0.9; | |
| const tl = gsap.timeline({repeat: -1}); | |
| // Animate each line in a loop | |
| splitLines.forEach((split, index) => { | |
| tl.fromTo( | |
| split.chars, | |
| { rotationX: -90 }, | |
| { rotationX: 90, stagger: 0.08, duration: animTime, ease: "none", transformOrigin }, | |
| index * 0.45 // stagger between lines | |
| ); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script src="https://unpkg.com/gsap@3/dist/gsap.min.js"></script> | |
| <script src="https://assets.codepen.io/16327/SplitText3.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| html { | |
| box-sizing: border-box; | |
| } | |
| *, | |
| *:before, | |
| *:after { | |
| box-sizing: inherit; | |
| } | |
| body, | |
| html { | |
| height: 100%; | |
| width: 100%; | |
| margin: 0; | |
| padding: 0; | |
| } | |
| .container { | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| width: 100%; | |
| height: 100%; | |
| visibility: hidden; | |
| } | |
| .tube { | |
| position: relative; | |
| width: 100%; | |
| height: 24vw; | |
| } | |
| .line { | |
| position: absolute; | |
| top: 50%; | |
| left: 50%; | |
| transform: translate(-50%, -50%); | |
| line-height: 1; | |
| margin: 0; | |
| letter-spacing: -0.6vw; | |
| font-size: 18vw; | |
| white-space: nowrap; | |
| text-align: center; | |
| } | |
| .line div { | |
| backface-visibility: hidden; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <link href="https://codepen.io/GreenSock/pen/xxmzBrw/fcaef74061bb7a76e5263dfc076c363e.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment