.
Skip to live previewA free futuristic GSAP 3 button with interactive 3D tilt and magnetic pull on mousemove, dynamic cursor-following glow, sweeping shine on hover, ripple effect, colorful 15-particle burst on click, rotating conic-gradient aura ring, and click sound. Built with GSAP 3.12.5, HTML, and CSS. Full source code free.
Every GSAP call, CSS property, and math formula behind the Ultimate Stylish GSAP Button.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Ultimate Stylish GSAP Button</title> <!-- GSAP 3.12.5 + MotionPathPlugin (for gsap.utils) --> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/MotionPathPlugin.min.js"></script> <link rel="stylesheet" href="style.css" /> </head> <body> <!-- Rotating aurora background ring --> <div class="aura-ring"></div> <!-- Main button --> <button class="ultimate-btn" id="ultimateBtn"> <span>Awaken</span> <div class="shine"></div> <!-- Shine sweep element --> <div class="glow" id="glow"></div> <!-- Cursor-follow glow --> </button> <!-- Click sound (replace src with your own audio) --> <audio id="clickSound" src="https://assets.codepen.io/605876/click-blip.mp3"></audio> <script src="script.js"></script> </body> </html>
How the 3D tilt, magnetic pull, glow follow, particle burst, and GSAP ease functions work.
On mousemove, getBoundingClientRect() gives the button's position. Subtracting the button center from cursor position gives the offset. Dividing by 6 controls tilt intensity: tiltX = (mouseY - cy) / 6, tiltY = (cx - mouseX) / 6. Multiplying offset by 0.17 gives the magnetic pull distance. gsap.to applies rotationX, rotationY, x, y simultaneously at duration 0.7s with power3.out. transform-style: preserve-3d on the button CSS enables the 3D perspective effect.
The .glow div is a 350×350px radial-gradient circle inside the button at opacity 0 and pointer-events: none. In the mousemove handler, glow.style.left = mouseX + 'px' and glow.style.top = mouseY + 'px' update position instantly without any animation (direct style change = no latency). GSAP handles only the opacity fade-in (0.25s on enter) and fade-out (0.4s on leave), so the light appears to illuminate exactly where the cursor is while smoothly appearing and disappearing at the button boundary.
The .shine div is a diagonal white gradient positioned off-screen to the left. gsap.fromTo(shine, {x: -350}, {x: 400, duration: 1.5, ease: 'power2.inOut'}) gives explicit start and end positions — more reliable than gsap.to alone since it guarantees the element starts at -350 regardless of interruption. power2.inOut provides natural acceleration and deceleration. The button's overflow: hidden clips the shine to the button area, so only the crossing portion is visible as the sweeping highlight.
On click, a loop runs 15 times. Each iteration creates a .particle div, assigns a random color from the array, positions it at mouseX/mouseY. gsap.to animates x to gsap.utils.random(-130, 130) for horizontal spread, y to gsap.utils.random(-180, -100) forcing upward movement, and rotation to gsap.utils.random(-720, 720) for multi-spin. opacity fades to 0 over 1.5s with power2.out. The onComplete callback removes each particle from the DOM to prevent memory buildup after repeated clicks.
The .aura-ring is a 280×280px absolutely-positioned div with border-radius: 50% and a conic-gradient cycling through purple, pink, and electric blue at low opacity (0.3–0.35 rgba). filter: blur(50px) spreads the colors into a soft diffused glow cloud. @keyframes spin rotates it 0→360deg over 7 seconds with linear timing and infinite repetition. z-index: -2 places it behind the button. The result is an ambient aurora that signals the button's interactivity without being distracting.
CSS animations excel for repeating loops (the aura spin) and simple hover transitions. GSAP is better for real-time interactions because: (1) back.out(1.6) provides a physical spring overshoot on scale that CSS lacks, (2) power3.out gives precise control over deceleration curves, (3) GSAP handles mid-animation interruption cleanly — mouseleave mid-hover properly reverses without a jump, (4) gsap.utils.random provides a clean API for dynamic values, and (5) chaining multiple properties (x, y, rotationX, rotationY, scale, boxShadow) in one call is much cleaner than CSS transitions.
Free courses in JavaScript, HTML, CSS, Python, SQL, DSA, Kotlin, C, C++, C#. Zero account needed.