Property Tweens.
Interpolate position, rotation, and scale in one tween.
View code
<script src="https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/gsap.min.js"></script>
<div class="stage large visible family-1" aria-label="tween animation"></div>:root{color-scheme:dark;color:#f3f1e9;font:15px Arial,sans-serif}body{margin:0;background:#111}.stage{width:100%}
.stage{height:185px;display:grid;place-items:center;position:relative;isolation:isolate;overflow:hidden;border-bottom:1px solid #ffffff26;background-color:#24291b;background-image:linear-gradient(#ffffff0c 1px,transparent 1px),linear-gradient(90deg,#ffffff0c 1px,transparent 1px);background-size:22px 22px;color:var(--lime)}.family-1{background-color:#281f32;color:#e1b8ff}.family-2{background-color:#192935;color:#9fdfff}.stage canvas{display:block;width:100%;height:100%;position:absolute;inset:0}
.shape{width:76px;aspect-ratio:1;display:grid;place-items:center;background:currentColor;border-radius:20%;box-shadow:0 0 36px #ffffff20}.shape b{color:#161616;font-size:27px}.large .shape{width:110px}.stage [class*=css-]{animation-duration:2.5s;animation-iteration-count:infinite;animation-timing-function:ease-in-out}.stage:not(.visible) [class*=css-],.stage.paused [class*=css-]{animation-play-state:paused}.stage .css-fade{animation-name:fade}.stage .css-slide{animation-name:slide}.stage .css-scale{animation-name:scale}.stage .css-spin{animation:spin 4s linear infinite;border-radius:50% 12% 50% 12%}.stage .css-bounce{animation-name:bounce;transform-origin:bottom}.stage .css-flip{animation-name:flip;transform-style:preserve-3d}.stage .css-mask{animation-name:mask;border-radius:50%}.stage .css-gradient{animation-name:gradient;background:linear-gradient(120deg,#f98563,#f2ec85,#89ffd5,#a481f4);background-size:330% 330%;width:60%;height:55%;border-radius:10px}.stage .css-marquee{animation:marquee 7s linear infinite;width:max-content;position:absolute;left:0;font-size:clamp(26px,5vw,70px);font-weight:900;white-space:nowrap}.css-hover{transition:transform .45s,background .45s;border:0}.css-hover:is(:hover,:focus-visible,[aria-pressed=true]),.card:hover .css-hover{transform:rotate(-14deg) scale(1.22);background:#ff8f65}.clip{overflow:hidden;padding:12px}.cluster{display:flex;align-items:center;justify-content:center;gap:8px;width:80%;max-width:500px}.cluster i{width:28px;aspect-ratio:1;background:currentColor;border-radius:6px;display:block}.cluster.matrix{display:grid;grid-template-columns:repeat(5,1fr);width:auto}.cluster.matrix i{width:19px}.letters{font-size:clamp(22px,4vw,66px);font-weight:900;letter-spacing:-.08em;display:flex}.diagram{width:min(85%,600px);max-height:85%;overflow:visible}.scrubber{height:85%;width:min(86%,500px);overflow:auto;border:1px solid #ffffff55;position:relative}.scroll-track{height:440px}.scroll-view{position:sticky;top:0;height:130px;display:grid;place-items:center}.flip-grid{display:flex;gap:10px;align-items:center}.flip-grid.changed{flex-direction:row-reverse;gap:24px}.flip-grid i{width:42px;aspect-ratio:1;background:#e1b8ff;border-radius:10px}.flip-grid i:nth-child(2){background:#a8e4fa}.flip-grid i:nth-child(3){background:#dbff55}.stage-action{position:absolute;bottom:12px;background:#191919;border:1px solid #ffffff55;border-radius:20px;padding:8px 12px;font-size:12px}.drag-area{height:72%;width:75%;border:1px dashed #ffffff55;display:grid;place-items:center}.drag-area .shape{touch-action:none;cursor:grab;border:0}.easing{display:grid;gap:9px;width:min(72%,350px)}.easing div{border-bottom:1px solid #ffffff50;font:11px Consolas,monospace;padding-bottom:3px}.easing i{display:block;width:14px;aspect-ratio:1;background:currentColor;border-radius:50%}.notice{padding:16px;text-align:center}
@keyframes fade{0%,100%{opacity:.2}50%{opacity:1}}@keyframes slide{0%,100%{transform:translateY(125%)}50%,65%{transform:translateY(0)}}@keyframes scale{0%,100%{transform:scale(.65)}50%{transform:scale(1.25)}}@keyframes spin{to{transform:rotate(360deg)}}@keyframes bounce{0%,100%{transform:translateY(32px) scale(1.14,.75)}47%{transform:translateY(-36px) scale(.9,1.12)}82%{transform:translateY(32px)}}@keyframes flip{0%,100%{transform:perspective(360px) rotateY(0)}50%{transform:perspective(360px) rotateY(180deg)}}@keyframes mask{0%,100%{clip-path:circle(8%)}50%{clip-path:circle(72%)}}@keyframes gradient{0%,100%{background-position:0% 50%}50%{background-position:100% 50%}}@keyframes marquee{to{transform:translateX(-50%)}}
.stage.large{height:100dvh}.stage :focus-visible{outline:2px solid #dbff55;outline-offset:3px}const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches;
const shape = (name = '', label = '✳') => `<div class="shape ${name}"><b>${label}</b></div>`;
const outline = 'M15 75 C65 -5 130 145 185 70 S255 25 285 65';
const pluginNames = {path:'MotionPathPlugin',scroll:'ScrollTrigger',layout:'Flip',drag:'Draggable',draw:'DrawSVGPlugin',physics:'Physics2DPlugin',morph:'MorphSVGPlugin',text:'SplitText'};
const diagram = (content) => `<svg class="diagram" viewBox="0 0 300 140" aria-hidden="true">${content}</svg>`;
const tiles = (count) => '<i></i>'.repeat(count);
function gsapDemo(stage, id, detail) {
const g = window.gsap;
const plugin = pluginNames[id];
const special = detail && plugin;
if (!g || (special && !window[plugin])) {
stage.innerHTML = '<p class="notice">This demo needs the GSAP library. Check your connection and reload.</p>';
return null;
}
if (special) g.registerPlugin(window[plugin]);
if (detail && id === 'drag') g.registerPlugin(InertiaPlugin);
const cluster = (count, matrix = '') => `<div class="cluster ${matrix}">${tiles(count)}</div>`;
const track = diagram(`<path class="route" d="${outline}" fill="none" stroke="currentColor" stroke-opacity=".45" stroke-dasharray="4 5"/><circle class="orb" cx="15" cy="75" r="8" fill="currentColor"/>`);
const contents = {
stagger: cluster(20, 'matrix'),
timeline: cluster(3),
ease: '<div class="easing">' + ['Linear','Elastic','Stepped'].map(label => `<div>${label}<i></i></div>`).join('') + '</div>',
text: '<div class="letters" aria-label="WEBTATTVA">' + [...'WEBTATTVA'].map(letter => `<span aria-hidden="true">${letter}</span>`).join('') + '</div>',
path: track,
scroll: detail ? `<div class="scrubber" tabindex="0" aria-label="Scroll inside to animate"><div class="scroll-track"><div class="scroll-view">${shape('', '↓')}</div></div></div>` : shape('', '↓'),
layout: `<div class="flip-grid">${tiles(3)}</div>${detail ? '<button class="stage-action">Switch layout</button>' : ''}`,
drag: `<div class="drag-area">${detail ? '<button class="shape" aria-label="Draggable tile. Use arrow keys to move."><b>✥</b></button>' : shape('', '✥')}</div>`,
draw: diagram(`<path d="${outline}" fill="none" stroke="currentColor" stroke-width="5" stroke-linecap="round"/>`),
morph: diagram('<path d="M150 10 L201 110 L99 110 Z" fill="currentColor"/>')
};
stage.innerHTML = contents[id] ?? shape();
const el = selector => stage.querySelector(selector);
const all = selector => [...stage.querySelectorAll(selector)];
const tile = el('.shape');
const tween = (target, vars) => g.to(target,{duration:1.2, repeat:-1, yoyo:true, repeatDelay:.2, paused:true,...vars});
let animation;
switch (id) {
case 'tween':
g.set(tile,{x:-50,rotation:-35});
animation = tween(tile,{x:50,rotation:155,scale:.65,ease:'power2.inOut'});
break;
case 'stagger':
animation = tween(all('i'),{scale:.3,opacity:.22,stagger:{grid:[4,5],from:'center',amount:.65}});
break;
case 'timeline':
animation = g.timeline({repeat:-1,yoyo:true,paused:true,repeatDelay:.25});
all('i').forEach((item,i) => animation.to(item,{y:-43,rotation:90,scale:1.3,duration:.52,ease:'back.out(2)'},i*.28));
break;
case 'ease':
animation = g.timeline({repeat:-1,yoyo:true,paused:true,repeatDelay:.3});
all('i').forEach((item,i) => animation.to(item,{x:()=>item.parentElement.clientWidth-14,ease:['none','elastic.out(1,.35)','steps(7)'][i],duration:1.45},0));
break;
case 'text':
animation = g.timeline({repeat:-1,paused:true,repeatDelay:.35});
if (detail) el('.letters').textContent = 'WEBTATTVA';
const letters = detail ? SplitText.create(el('.letters'),{type:'chars'}).chars : all('span');
animation.from(letters,{y:36,opacity:0,stagger:.065,duration:.52}).to(letters,{y:-28,opacity:0,stagger:.04,duration:.35},'+=.5');
break;
case 'path': {
const route = el('.route');
const orb = el('.orb');
const progress = {value:0};
animation = special
? tween(orb,{motionPath:{path:route,align:route,alignOrigin:[.5,.5]},duration:2.3,ease:'none'})
: tween(progress,{value:1,duration:2.3,ease:'none',onUpdate() {
const point = route.getPointAtLength(progress.value*route.getTotalLength());
orb.setAttribute('cx',point.x);
orb.setAttribute('cy',point.y);
}});
break;
}
case 'scroll': {
if (!detail) {
animation = tween(tile,{x:65,rotation:270,scale:.5});
break;
}
const scroller = el('.scrubber');
g.to(tile,{rotation:360,scale:.45,ease:'none',scrollTrigger:{trigger:el('.scroll-track'),scroller,start:'top top',end:'bottom bottom',scrub:true}});
return null;
}
case 'layout':
if (detail) {
el('button').onclick = () => {
const state = Flip.getState(all('i'));
el('.flip-grid').classList.toggle('changed');
Flip.from(state,{duration:reduced ? 0 : .65,ease:'power2.inOut'});
};
return null;
}
animation = tween(all('i'),{x:i=>[104,0,-104][i],rotation:180,stagger:.07});
break;
case 'drag':
if (detail) {
const [drag] = Draggable.create(tile,{
bounds:el('.drag-area'), inertia:true, edgeResistance:.82,
snap:{x:value=>Math.round(value/20)*20,y:value=>Math.round(value/20)*20}
});
tile.addEventListener('keydown',event=>{
const delta = {ArrowLeft:[-12,0],ArrowRight:[12,0],ArrowUp:[0,-12],ArrowDown:[0,12]}[event.key];
if (!delta) return;
event.preventDefault();
drag.tween?.kill();
g.set(tile,{x:drag.x+delta[0],y:drag.y+delta[1]});
drag.update(true);
});
return null;
}
animation = tween(tile,{x:45,y:-20,rotation:18});
break;
case 'draw': {
const line = el('path');
if (special) {
g.set(line,{drawSVG:'0%'});
animation = tween(line,{drawSVG:'100%'});
} else {
const length = line.getTotalLength();
g.set(line,{strokeDasharray:length,strokeDashoffset:length});
animation = tween(line,{strokeDashoffset:0});
}
break;
}
case 'physics':
if (special) animation = g.to(tile,{physics2D:{velocity:255,angle:-65,gravity:410},rotation:170,ease:'none',duration:1.13,repeat:-1,repeatDelay:.35,paused:true});
else animation = tween(tile,{keyframes:[{x:25,y:-48},{x:55,y:0}],ease:'none'});
break;
case 'morph':
if (special) animation = tween(el('path'),{morphSVG:'M150 7 L170 46 L215 51 L182 83 L190 128 L150 106 L110 128 L118 83 L85 51 L130 46 Z'});
else animation = tween(el('path'),{attr:{d:'M84 44 L216 44 L150 130 Z'}});
break;
}
return {
play(active) { animation.paused(!active); },
reset() { animation.totalTime(0); }
};
}
const stage = document.querySelector('.stage');
const controller = gsapDemo(stage, 'tween', true);
controller?.play(!reduced);