GSAP 사례 연구
Draw a path
테두리 · MIT (local companion); GSAP Standard No Charge License (runtime)
갤러리 안에서는 화면을 벗어나거나 움직임을 멈추면 예제도 닫힙니다. 다시 재생할 때는 처음부터 시작해요.
저장한 HTML에서는 갤러리의 재생 설정이 적용되지 않아요.
SOURCE FILES
독립 예제 코드 읽기
사례의 구도나 문서의 원리를 바탕으로 새로 만든 예제입니다. 아래 코드를 복사해 직접 응용할 수 있습니다. 실행 HTML에는 미리보기를 위한 실행 환경이 들어 있습니다.
vendor/gsap-previews/sources/gsap-b2a575a930f3/source-input.js
//draws all elements with the "draw-me" class applied
gsap.from(".draw-me", {duration:1,drawSVG: 0});vendor/gsap-previews/sources/gsap-b2a575a930f3/index.html실행 안내·자료
<main class="study"><p class="study-label">공식 문서 기반 · 독립 예제</p><header><h2>선의 길이를 드러내기</h2><p>새로 그린 세 경로에 동일한 1초 DrawSVG 호출을 적용합니다.</p></header><div class="stage"><svg viewBox="0 0 640 320" aria-label="곡선, 원, 지그재그 경로" role="img"><defs><linearGradient id="line-g" x2="1" y2="1"><stop stop-color="#95efd2"/><stop offset="1" stop-color="#b09aff"/></linearGradient></defs><g fill="none" stroke="url(#line-g)" stroke-linecap="round" stroke-width="7"><path class="draw-me" d="M45 235C45 50 225 45 225 225S45 280 140 150"/><circle class="draw-me" cx="360" cy="160" r="78"/><path class="draw-me" d="m500 70 80 0-60 90h75l-100 100"/></g></svg></div><div class="controls"><button id="draw" type="button">선 그리기</button></div></main>함께 쓰는 파일 3개 보기
vendor/gsap-previews/sources/gsap-b2a575a930f3/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{max-height:360px;width:100%}vendor/gsap-previews/sources/gsap-b2a575a930f3/script.js실행 안내·자료
gsap.registerPlugin(DrawSVGPlugin);
function draw(){gsap.killTweensOf('.draw-me');gsap.set('.draw-me',{drawSVG:'100%'});//draws all elements with the "draw-me" class applied
gsap.from(".draw-me", {duration:1,drawSVG: 0});
}
document.getElementById('draw').addEventListener('click',draw);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
이 장면을 만드는 원리
경로의 존재와 선의 표시 길이
눈에 보이는 변화와 실제로 바꾸는 속성을 구분합니다.
- 이 예제에서는
- 공식 코드는 .draw-me 요소에 drawSVG:0인 from 트윈을 1초 적용합니다. 동반 예제는 새로 그린 곡선·원·지그재그의 stroke를 대상으로 하며 path의 기하 자체를 바꾸지 않습니다. 재시작 전에는 표시 길이를 100%로 복원해 중간 상태를 도착점으로 잘못 캡처하지 않게 합니다.
코드와 함께 확인하기
코드에서 찾기
gsap.from(".draw-me"source-input.js같은 클래스의 선 표시를 0부터 드러내는 문서 호출입니다.
function drawscript.js이전 트윈을 정리하고 완성 길이를 복원한 뒤 문서 코드를 실행합니다.
직접 해보기
한 번 그리기를 끝냅니다.
살펴볼 변화세 선이 각자의 전체 기하를 표시해야 합니다.
선이 절반 보일 때 다시 실행합니다.
살펴볼 변화절반 길이에서 끝나지 않고 전체 선까지 다시 그려야 합니다.
