GSAP 사례 연구
Morph between SVG shapes
배경 · MIT (local companion); GSAP Standard No Charge License (runtime)
갤러리 안에서는 화면을 벗어나거나 움직임을 멈추면 예제도 닫힙니다. 다시 재생할 때는 처음부터 시작해요.
저장한 HTML에서는 갤러리의 재생 설정이 적용되지 않아요.
SOURCE FILES
독립 예제 코드 읽기
사례의 구도나 문서의 원리를 바탕으로 새로 만든 예제입니다. 아래 코드를 복사해 직접 응용할 수 있습니다. 실행 HTML에는 미리보기를 위한 실행 환경이 들어 있습니다.
vendor/gsap-previews/sources/gsap-0c2efd6b618f/source-input.js
gsap.to("#circle", { duration: 1, morphSVG: "#lightning" });vendor/gsap-previews/sources/gsap-0c2efd6b618f/index.html실행 안내·자료
<main class="study"><p class="study-label">공식 문서 기반 · 독립 예제</p><header><h2>두 경로 사이의 모양</h2><p>시작과 도착 경로는 새로 그렸습니다. 모핑 호출은 공식 문서의 한 줄을 사용합니다.</p></header><div class="stage"><svg viewBox="0 0 320 320" role="img" aria-label="원에서 번개로 변하는 모양"><defs><linearGradient id="morph-g" x2="1" y2="1"><stop stop-color="#fcabc9"/><stop offset="1" stop-color="#8980ff"/></linearGradient><path id="lightning" d="M176 28 73 179H145L120 292 248 129H176Z"/></defs><path id="circle" fill="url(#morph-g)" d="M160 48A112 112 0 1 1 160 272A112 112 0 1 1 160 48Z"/></svg></div><div class="controls"><button id="morph" type="button">모양 바꾸기</button></div></main>함께 쓰는 파일 3개 보기
vendor/gsap-previews/sources/gsap-0c2efd6b618f/style.css실행 안내·자료
*{box-sizing:border-box}body{background:#111522;color:#f5f2eb;font-family:system-ui,sans-serif;margin:0}button{font:inherit}.study{margin:0 auto;max-width:1100px;min-height:100vh;padding:clamp(20px,4vw,42px)}.study-label{color:#95efd2;font-size:12px;letter-spacing:.08em;margin:0 0 24px}header h2{font-size:clamp(24px,4vw,40px);letter-spacing:-.04em;margin:0 0 12px}header p{color:#aeb7c9;line-height:1.6;margin:0 0 24px;max-width:62ch}.controls{display:flex;flex-wrap:wrap;gap:8px;margin:20px 0}button{background:#26314b;border:1px solid #617394;border-radius:9px;color:#f5f2eb;cursor:pointer;padding:9px 14px}button:hover{background:#334261}button:focus-visible{outline:3px solid #95efd2;outline-offset:3px}button:disabled{cursor:default;opacity:.45}.stage{align-items:center;background:radial-gradient(ellipse at top,#243253,#141c2d);border:1px solid #3d4c68;border-radius:20px;display:flex;justify-content:center;min-height:220px;overflow:hidden;position:relative}.note{color:#aeb7c9;font-size:13px;line-height:1.5}.readout{color:#95efd2;font-family:ui-monospace,monospace;font-size:13px;min-height:2em}.stage svg{display:block;max-width:100%}code{font-family:ui-monospace,monospace}button[aria-pressed="true"]{background:#95efd2;color:#111522}
.stage svg{height:280px;width:280px}vendor/gsap-previews/sources/gsap-0c2efd6b618f/script.js실행 안내·자료
gsap.registerPlugin(MorphSVGPlugin);
const start=document.getElementById('circle').getAttribute('d');
function morph(){gsap.killTweensOf('#circle');gsap.set('#circle',{attr:{d:start}});gsap.to("#circle", { duration: 1, morphSVG: "#lightning" });
}
document.getElementById('morph').addEventListener('click',morph);LICENSE실행 안내·자료
Locally authored companion HTML/CSS/control wiring: MIT License.
Copyright (c) 2026 StyleGallery contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The separately retained official documentation excerpt is source input, not a recovered CodePen source set; this local MIT notice does not assign a new license to that excerpt.
GSAP 3.15.0: Copyright 2026, GreenSock. All rights reserved. Subject to https://gsap.com/standard-license. Original library notices are preserved.
BEHIND THE EXAMPLE
이 장면을 만드는 원리
문서의 끝점과 재시작 정책
새 재생이 현재 표현에서 이어질지 시작점으로 돌아갈지를 명시합니다.
- 이 예제에서는
- 공식 문서는 #circle을 #lightning으로 1초 동안 모핑합니다. 두 경로와 버튼은 독립 제작했으며 버튼은 시작 d를 복원한 뒤 해당 호출을 실행합니다. 따라서 중간 클릭은 같은 상태에서 되돌리기가 아니라 처음부터 다시 시연하기입니다.
코드와 함께 확인하기
코드에서 찾기
morphSVG: "#lightning"source-input.js공식 코드가 지정하는 도착 경로 선택자입니다.
function morphscript.js동반 예제가 시작 경로를 복원하고 새 시연을 시작합니다.
직접 해보기
재생이 끝날 때까지 기다립니다.
살펴볼 변화새로 그린 번개 경로로 끝나야 합니다.
중간에 다시 누릅니다.
살펴볼 변화시작 경로로 돌아가 재생한다는 명시된 정책과 일치해야 합니다.
