Codrops 원본
Made With Gsap: Building a Fun Gravity-Based Mouse Trail
섹션 · MIT
갤러리 안에서는 화면을 벗어나거나 움직임을 멈추면 예제도 닫힙니다. 다시 재생할 때는 처음부터 시작해요.
SOURCE FILES
원본 코드 읽기
수집한 원본 소스와 실행 안내를 함께 제공합니다.
assets/script.js
window.addEventListener("DOMContentLoaded", () => {
const root = document.querySelector('.codrops_mwg')
const images = []
root.querySelectorAll('.medias img').forEach(image => {
images.push(image.getAttribute('src'))
})
let incr = 0,
oldIncrX = 0,
oldIncrY = 0,
firstMove = true,
indexImg = 0
const isCoarsePointer = window.matchMedia('(hover: none)').matches
const resetDist = window.innerWidth / (isCoarsePointer ? 6 : 8)
const W = window.innerWidth
const H = window.innerHeight
const clampX = gsap.utils.clamp(0, W)
const clampY = gsap.utils.clamp(0, H)
function applyMove(clientX, clientY) {
const valX = clampX(clientX)
const valY = clampY(clientY)
if (firstMove) {
firstMove = false
oldIncrX = valX
oldIncrY = valY
return
}
incr += Math.abs(valX - oldIncrX) + Math.abs(valY - oldIncrY)
if (incr > resetDist) {
incr = 0
createMedia(valX, valY - root.getBoundingClientRect().top, valX - oldIncrX, valY - oldIncrY)
}
oldIncrX = valX
oldIncrY = valY
}
function handleMouseMove(e) {
applyMove(e.clientX, e.clientY)
}
function handleTouchMove(e) {
if (!e.touches || !e.touches[0]) return
applyMove(e.touches[0].clientX, e.touches[0].clientY)
}
root.addEventListener('mousemove', handleMouseMove)
root.addEventListener('touchstart', handleTouchMove, { passive: true })
root.addEventListener('touchmove', handleTouchMove, { passive: true })
function createMedia(x, y, deltaX, deltaY) {
const H = window.innerHeight
if (y > H - 200) return
const image = document.createElement("img")
image.setAttribute('src', images[indexImg])
root.appendChild(image)
const tl = gsap.timeline({
onComplete: () => {
root.removeChild(image);
tl && tl.kill()
}
})
tl.fromTo(image, {
xPercent: -50 + (Math.random() - 0.5) * 80,
yPercent: -50 + (Math.random() - 0.5) * 10,
scaleX: 1.3,
scaleY: 1.3,
rotation:(Math.random() - 0.5) * 20
}, {
scaleX:1,
scaleY:1,
ease: 'elastic.out(2, 0.6)',
duration: 0.4
})
tl.fromTo(image, {
x,
}, {
x: '+=' + deltaX * 2,
rotation: 0,
ease: 'power1.in',
duration: 0.4
}, '<')
tl.fromTo(image, {
y
}, {
y: '+=' + (H - y),
scale: 0.9,
yPercent: -95, // pour que le bord bas s'arrête pile au bas du viewport combiné avec le scale a 0.9
ease: 'back.in(1.1)',
duration: 0.4
}, '<')
// BOUNCE
tl.to(image, {
x: '+=' + deltaX * 1.6,
rotation:(Math.random() - 0.5) * 40,
ease: 'power1.in',
duration: 0.3
})
tl.to(image, {
yPercent: 150,
ease: 'back.in(' + (1.5 + (1 - y/H)) + ')',
duration: 0.3
}, '<')
indexImg = (indexImg + 1) % images.length
}
// KILL
const observer = new MutationObserver(mutations => {
const isRootRemoved = mutations.some(mutation =>
mutation.type === 'childList' &&
Array.from(mutation.removedNodes).includes(root)
)
if (isRootRemoved) {
root.removeEventListener('mousemove', handleMouseMove)
root.removeEventListener('touchstart', handleTouchMove, { passive: true })
root.removeEventListener('touchmove', handleTouchMove, { passive: true })
observer.disconnect()
}
})
observer.observe(document.body, {childList: true, subtree: true})
})assets/style.css
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@500;800&display=swap');
/* NORMALIZE */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
appearance: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* NORMALIZE */
body {
background: #121212;
color: #F1F1F1;
font: 500 normal 22px/1.3 'Inter', sans-serif;
}
/* to prevent scroll bumps, remove this if you want to keep the flow of the page */
html:has(.codrops_mwg),
body:has(.codrops_mwg) {
overflow: hidden;
}
.codrops_mwg {
height: 100dvh;
overflow: hidden;
position: relative;
}
.codrops_mwg .content-effect {
font-size: min(60px, 5.6vw);
text-align: center;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
position: absolute;
align-items: center;
letter-spacing: -0.03em;
span {
display: block;
width: max-content;
}
span:last-child {
color: #999;
}
}
.codrops_mwg img {
width: 15vw;
height: 15vw;
position: absolute;
object-fit: cover;
border-radius: 4%;
z-index: 5;
}
.codrops_mwg .medias img {
width: 1px;
height: 1px;
top: 0;
left: 0;
position: absolute;
visibility: hidden;
pointer-events: none;
}
@media (max-width: 768px) {
.codrops_mwg img {
width: 35vw;
height: 35vw;
}
}함께 쓰는 파일 3개 보기
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Codrops — Made With Gsap</title>
<link rel="stylesheet" href="assets/style.css">
<link rel="icon" type="image/png" href="assets/favicon-96x96.png" sizes="96x96" />
</head>
<body>
<section class="codrops_mwg">
<p class="content-effect">
<span>Move your mouse to make</span>
<span>images fall and bounce</span>
</p>
<div class="medias">
<img src="assets/medias/01.png" alt="">
<img src="assets/medias/02.png" alt="">
<img src="assets/medias/03.png" alt="">
<img src="assets/medias/04.png" alt="">
<img src="assets/medias/05.png" alt="">
<img src="assets/medias/06.png" alt="">
<img src="assets/medias/07.png" alt="">
<img src="assets/medias/08.png" alt="">
<img src="assets/medias/09.png" alt="">
<img src="assets/medias/10.png" alt="">
</div>
</section>
<!-- GSAP -->
<script src="https://cdn.jsdelivr.net/npm/gsap@3.15/dist/gsap.min.js"></script>
<!-- EFFECT CODE -->
<script src="assets/script.js"></script>
</body>
</html>Original author attribution실행 안내·자료
Made With Gsap: Building a Fun Gravity-Based Mouse Trail
Original author: Made With Gsap
Published by Codrops. Copyright (c) 2026 Codrops.
License: MIT, pursuant to the publisher's downloadable-demo grant.
Keep CODROPS-MIT-2026.txt and the original project notices with copies.
Third-party media exceptions and credits are recorded separately in the source inventory.
Bundled dependency licenses실행 안내·자료
GSAP standard license snapshot
Source: https://gsap.com/community/standard-license/
Retrieved: 2026-09-22T04:22:49.089Z
Original distribution copyright and version headers remain in the runtime code.
Standard "No Charge" GSAP License
I. DEFINITIONS
“GSAP License” means the terms and conditions of this GSAP Software License Agreement.
"GSAP Products" means any Software made available at gsap.com (https://gsap.com) or any successor sites, including but not limited to the GSAP animation library and related plugins, tools, or extensions.
"Permitted Uses" means the implementation and/or use of GSAP Products on any website, web application, or digital interface by any person or entity (which may include, for clarity, those of companies that compete with Webflow in other areas of business).
"Prohibited Uses" means any implementation and/or use of GSAP Products in tools that allow users to build visual animations without code that encourages, induces, or materially assists in creating a solution that competes with Webflow’s visual animation building capabilities.
"Competitive Products" means any software, tool, or service that enables users to create, edit, or manage animations through a visual interface or builder similar to Webflow (https://webflow.com).
II. GRANT OF LICENSE
Subject to the terms and conditions of this GSAP License, Webflow grants you a non-exclusive, worldwide license to use, reproduce, display, and implement GSAP Products solely for Permitted Uses.
III. RESTRICTIONS
You may not:
Use any GSAP Products for any Prohibited Uses without prior written consent;
Reverse engineer any GSAP Products for the purpose of creating Competitive Products;
Remove or alter any proprietary notices or branding from GSAP Products.
IV. OWNERSHIP AND INTELLECTUAL PROPERTY
All intellectual property rights in GSAP Products, including but not limited to copyright, patents, trademarks, and trade secrets, remain the exclusive property of Webflow. This GSAP License does not transfer any ownership rights in GSAP Products to you.
V. TERMINATION
Webflow may terminate this GSAP License and revoke your access in its discretion if you fail to comply with any of these terms and conditions. Upon termination, you must cease all use of GSAP Products and destroy all copies in your possession.
VI. MISCELLANEOUS PROVISIONS
General: This GSAP License is incorporated into and subject to Webflow’s Terms of Service available here (https://webflow.com/legal/terms) ("Terms of Service"). In the event of any conflict or inconsistency between this GSAP License and the Terms of Service, the terms of this GSAP License shall govern in relation to your use of any GSAP Products.
Amendments: Webflow reserves the right to update or modify this GSAP License at any time by posting the revised terms on this website, provided that any such updates or modifications shall not result in any material degradation to the security, integrity, or functionality of any GSAP Products. You understand and agree that your continued use of any GSAP Products after such revisions to this GSAP License constitutes your acceptance of this GSAP License as revised. If you do not accept the revised GSAP License, you are prohibited from using versions of the GSAP Products released after the effective date of the revised GSAP License (as well as any updates made to previous versions). Notwithstanding, you may continue using previous versions of GSAP Products under the applicable terms licensed to you prior to the effective date of the revised GSAP License (for clarity, excluding any updates made thereto).
No Waiver: Failure of Webflow to enforce any provision of this GSAP License shall not constitute a waiver of future enforcement of that or any other provision.
FAQ
Is it acceptable for AI tools like ChatGPT, Cursor, Lovable, Webstudio, etc. to generate GSAP code?
Absolutely! AI-generated code is not a "Prohibited Use".
What if a WordPress plugin or theme or other niche tool allows users to create GSAP-driven effects through a visual interface? Is that prohibited?
We want to encourage developers to build on top of GSAP, including visual tools that don't directly compete with Webflow's rich animation-building capabilities. If you are not sure if your product might be considered a "Prohibited Use", feel free to contact us (https://gsap.com/contact) so we can talk through it!
Can I really use GSAP in commercial projects without paying anything?
Yes, really! Commercial usage is covered under the standard license. All of GSAP including the plugins that were formerly "members-only" like SplitText (https://gsap.com/docs/v3/Plugins/SplitText/) and MorphSVG (https://gsap.com/docs/v3/Plugins/MorphSVGPlugin) can be used in commercial projects at no charge. Enjoy! 💚
Effective date: April 30, 2025
Last modified date: May 30, 2025
Copyright (©) 2025, Webflow
BEHIND THE EXAMPLE
이 장면을 만드는 원리
포인터 누적 거리로 한 장씩 만드는 낙하 꼬리
입력·상태·출력·수명과 실제 결과를 명시합니다.
- 이 예제에서는
- applyMove는 처음 입력을 기준점으로만 저장하고 이후 x·y 이동의 절댓값 합을 누적합니다. 초기 화면 폭의 1/6 또는 1/8을 넘으면 한 장을 만들고 누적값을 0으로 지웁니다. createMedia는 아래 200px 구간의 생성을 건너뜁니다.
