Codrops 원본
Grid Zoom Layout
섹션 · MIT
갤러리 안에서는 화면을 벗어나거나 움직임을 멈추면 예제도 닫힙니다. 다시 재생할 때는 처음부터 시작해요.
SOURCE FILES
원본 코드 읽기
수집한 원본 소스와 실행 안내를 함께 제공합니다.
src/css/base.css
*,
*::after,
*::before {
box-sizing: border-box;
}
:root {
font-size: 15px;
}
body {
margin: 0;
--color-text: #000;
--color-bg: #f7f5ee;
--color-link: #000;
--color-link-hover: #000;
color: var(--color-text);
background-color: var(--color-bg);
font-family: rustica, -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
overflow: hidden;
overflow-y: scroll;
line-height: 1;
}
/* Page Loader */
.js .loading::before,
.js .loading::after {
content: '';
position: fixed;
z-index: 1000;
}
.js .loading::before {
top: 0;
left: 0;
width: 100%;
height: 100%;
background: var(--color-bg);
}
.js .loading::after {
top: 50%;
left: 50%;
width: 60px;
height: 60px;
margin: -30px 0 0 -30px;
border-radius: 50%;
opacity: 0.4;
background: var(--color-link);
animation: loaderAnim 0.7s linear infinite alternate forwards;
}
@keyframes loaderAnim {
to {
opacity: 1;
transform: scale3d(0.5,0.5,1);
}
}
a {
text-decoration: none;
color: var(--color-link);
outline: none;
font-weight: 600;
}
a:hover {
color: var(--color-link-hover);
outline: none;
}
/* Better focus styles from https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible */
a:focus {
/* Provide a fallback style for browsers
that don't support :focus-visible */
outline: none;
background: lightgrey;
}
a:focus:not(:focus-visible) {
/* Remove the focus indicator on mouse-focus for browsers
that do support :focus-visible */
background: transparent;
}
a:focus-visible {
/* Draw a very noticeable focus style for
keyboard-focus on browsers that do support
:focus-visible */
outline: 2px solid red;
background: transparent;
}
.unbutton {
background: none;
border: 0;
padding: 0;
margin: 0;
font: inherit;
}
.unbutton:focus {
outline: none;
}
.line {
transform-origin: 0% 50%;
padding-bottom: 0.35rem;
white-space: nowrap;
will-change: transform;
}
.oh {
overflow: hidden;
}
.oh__inner {
display: inline-block;
transform-origin: 0% 50%;
will-change: transform;
}
.frame {
height: 100%;
display: flex;
flex-direction: column;
align-items: flex-start;
}
.frame--fixed {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: auto;
padding: 1rem;
z-index: 1;
display: grid;
grid-template-columns: 38% 62%;
}
.frame__title {
font-size: 1rem;
font-weight: 400;
margin: 0 0 2rem 0;
}
.frame__links {
display: flex;
flex-direction: column;
align-items: flex-start;
}
.frame__links a {
margin: 0 1rem 0.35rem 0;
}
.frame--fixed .frame__links {
flex-direction: row;
}
.grid {
display: grid;
--grid-border-radius: 8px;
grid-template-columns: repeat(2,50%);
}
.grid--large {
grid-auto-rows: 32vmin;
padding: 0.5vw;
--grid-padding: 0.5vw;
}
.grid--mini {
width: 220px;
height: 190px;
--grid-padding: 1px;
margin-bottom: 3vh;
pointer-events: none;
opacity: 0;
visibility: hidden;
pointer-events: none;
position: absolute;
}
.grid__cell {
display: grid;
align-items: end;
}
.grid--mini .grid__cell:not(.grid__cell--current):hover .grid__cell-img {
opacity: 0.7;
}
.grid__cell--current .grid__cell-img {
opacity: 0.3;
}
.grid__cell--padded {
padding: calc(var(--grid-padding) * 2 );
}
.grid__cell-img {
width: calc(100% - var(--grid-padding) * 2);
height: calc(100% - var(--grid-padding) * 2);
margin: var(--grid-padding);
border-radius: var(--grid-border-radius);
display: block;
position: relative;
overflow: hidden;
}
.grid__cell-img-inner {
background-size: cover;
background-position: 50% 50%;
width: 100%;
height: 100%;
cursor: pointer;
}
.content {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
padding: 15vh 8vw 0;
z-index: 1000;
pointer-events: none;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.content__item {
position: absolute;
opacity: 0;
display: grid;
}
.content__item--current {
opacity: 1;
position: relative;
pointer-events: auto;
}
.content__item-number {
font-weight: 600;
display: block;
}
.content__item-heading {
font-size: 4vw;
line-height: 1;
margin: 1rem 0 3rem 0;
font-weight: 600;
}
.content__item-text {
max-width: 30ch;
margin-bottom: 2rem;
}
.content__item-link {
cursor: pointer;
}
.slide-nav {
position: fixed;
width: 40%;
right: 15%;
top: 0;
height: 100%;
display: grid;
align-content: space-between;
pointer-events: none;
}
.slide-nav__img {
width: 100%;
height: 10vh;
position: relative;
overflow: hidden;
opacity: 0.3;
cursor: not-allowed;
}
.content--open .slide-nav__img {
pointer-events: auto;
}
.slide-nav__img--prev {
transform: translateY(-100%);
border-radius: 0 0 1.5vw 1.5vw;
}
.slide-nav__img--next {
transform: translateY(100%);
border-radius: 1.5vw 1.5vw 0 0;
}
.slide-nav__img-inner {
width: 100%;
height: 100%;
background-size: cover;
background-position: 50% 50%;
}
.back {
background: none;
border: 0;
padding: 0;
margin: auto 0 1.5rem 0;
opacity: 0;
pointer-events: none;
stroke: #000;
z-index: 1000;
cursor: pointer;
width: 50px;
}
.back svg {
stroke-linecap: round;
}
.back:hover,
.back:focus {
outline: none;
stroke: #823725;
}
.content--open .back {
pointer-events: auto;
}
@media screen and (min-width: 53em) {
.content {
width: 38%;
}
.grid {
grid-template-columns: repeat(4,25%);
}
.grid__cell--padded {
padding: var(--grid-padding);
}
.grid__cell-c1-r1 { grid-column: 1; grid-row: 1; }
.grid__cell-c3-r1 { grid-column: 3; grid-row: 1; }
.grid__cell-c4-r1 { grid-column: 4; grid-row: 1; }
.grid__cell-c1-r2 { grid-column: 1; grid-row: 2; }
.grid__cell-c2-r2 { grid-column: 2; grid-row: 2; }
.grid__cell-c3-r2 { grid-column: 3; grid-row: 2; }
.grid__cell-c4-r2 { grid-column: 4; grid-row: 2; }
.grid__cell-c2-r3 { grid-column: 2; grid-row: 3; }
.grid__cell-c4-r3 { grid-column: 4; grid-row: 3; }
.grid__cell-c1-r4 { grid-column: 1; grid-row: 4; }
.grid__cell-c3-r4 { grid-column: 3; grid-row: 4; }
.grid__cell-c3-r5 { grid-column: 3; grid-row: 5; }
.grid--mini {
visibility: visible;
position: relative;
}
.content--open .grid--mini {
pointer-events: auto;
}
body #cdawrap {
position: relative;
margin-top: auto;
--cda-left: auto;
--cda-right: auto;
--cda-width: 300px;
--cda-bottom: auto;
--cda-top: auto;
opacity: 1 !important;
pointer-events: auto;
z-index: 1;
}
body #cdawrap .cda-footer {
display: none;
}
body #cdawrap .cda-text {
color: transparent !important;
height: 1.25rem;
pointer-events: none;
position: relative;
text-align: left;
}
body #cdawrap .cda-text::before {
color: var(--color-text);
content: "Sponsored by "attr(data-sponsor);
font-size: 0.85rem;
font-weight: 500;
left: 0;
pointer-events: auto;
position: absolute;
top: 0;
opacity: 0.5;
transition: opacity 0.4s;
}
.grid[style*="pointer-events: none;"] .frame #cdawrap .cda-text::before {
opacity: 0 !important;
}
body #cdawrap:hover .cda-text::before {
color: var(--color-link-hover);
}
body #cdawrap a::after {
display: none;
}
}
src/index.html
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Grid Zoom | Codrops</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="Codrops" />
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="https://use.typekit.net/jyi8res.css">
<link rel="stylesheet" type="text/css" href="css/base.css" />
<script>document.documentElement.className="js";var supportsCssVars=function(){var e,t=document.createElement("style");return t.innerHTML="root: { --tmp-var: bold; }",document.head.appendChild(t),e=!!(window.CSS&&window.CSS.supports&&window.CSS.supports("font-weight","var(--tmp-var)")),t.parentNode.removeChild(t),e};supportsCssVars()||alert("Please view this demo in a modern browser that supports CSS Variables.");</script>
</head>
<body class="loading">
<main>
<div class="grid grid--large">
<div class="grid__cell grid__cell-c4-r2 grid__cell--padded">
<div class="frame">
<h1 class="frame__title oh"><span class="oh__inner">Grid Zoom Effect</span></h1>
<nav class="frame__links">
<a href="" class="oh"><span class="oh__inner">Article</span></a>
<a href="https://tympanus.net/Development/ParanoiaSlideshow/" class="oh"><span class="oh__inner">Previous demo</span></a>
<a href="https://github.com/codrops/GridZoom/" class="oh"><span class="oh__inner">GitHub</span></a>
</nav>
</div>
</div>
<div class="grid__cell grid__cell-c2-r2 grid__cell--padded">
<a href="https://twitter.com/codrops" class="oh"><span class="oh__inner">@codrops</span></a>
</div>
<div class="grid__cell grid__cell-c1-r1">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/1.jpg)" data-item="item-1"></div>
</div>
</div>
<div class="grid__cell grid__cell-c3-r1">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/2.jpg)" data-item="item-2"></div>
</div>
</div>
<div class="grid__cell grid__cell-c4-r1">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/3.jpg)" data-item="item-3"></div>
</div>
</div>
<div class="grid__cell grid__cell-c1-r2">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/4.jpg)" data-item="item-4"></div>
</div>
</div>
<div class="grid__cell grid__cell-c3-r2">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/5.jpg)" data-item="item-5"></div>
</div>
</div>
<div class="grid__cell grid__cell-c2-r3">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/6.jpg)" data-item="item-6"></div>
</div>
</div>
<div class="grid__cell grid__cell-c4-r3">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/7.jpg)" data-item="item-7"></div>
</div>
</div>
<div class="grid__cell grid__cell-c1-r4">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/8.jpg)" data-item="item-8"></div>
</div>
</div>
<div class="grid__cell grid__cell-c3-r4">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/9.jpg)" data-item="item-9"></div>
</div>
</div>
<div class="grid__cell grid__cell-c3-r5">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/10.jpg)" data-item="item-10"></div>
</div>
</div>
</div>
<div class="content">
<div class="content__item" id="item-1">
<span class="content__item-number oh"><span class="oh__inner">01</span></span>
<h2 class="content__item-heading oh"><span class="oh__inner">Masses</span></h2>
<p class="content__item-text">
The instruments by which public opinion is organized and focused may be misused. But such organization and focusing are necessary to orderly life.
</p>
<a class="content__item-link oh"><span class="oh__inner">View more</span></a>
<nav class="slide-nav">
<div class="slide-nav__img slide-nav__img--prev" style="background-image:url(img/11.jpg);"></div>
<div class="slide-nav__img slide-nav__img--next" style="background-image:url(img/12.jpg);"></div>
</nav>
</div>
<div class="content__item" id="item-2">
<span class="content__item-number oh"><span class="oh__inner">02</span></span>
<h2 class="content__item-heading oh"><span class="oh__inner">Invisible</span></h2>
<p class="content__item-text">
As civilization has become more complex, and as the need for invisible government has been increas ingly demonstrated, the technical means have been invented and developed by which opinion may be regimented.
</p>
<a class="content__item-link oh"><span class="oh__inner">View more</span></a>
<nav class="slide-nav">
<div class="slide-nav__img slide-nav__img--prev" style="background-image:url(img/13.jpg);"></div>
<div class="slide-nav__img slide-nav__img--next" style="background-image:url(img/14.jpg);"></div>
</nav>
</div>
<div class="content__item" id="item-3">
<span class="content__item-number oh"><span class="oh__inner">03</span></span>
<h2 class="content__item-heading oh"><span class="oh__inner">Expense</span></h2>
<p class="content__item-text">
The invisible government tends to be concentrated in the hands of the few because of the expense of manipulating the social machinery which controls the opinions and habits of the masses.
</p>
<a class="content__item-link oh"><span class="oh__inner">View more</span></a>
<nav class="slide-nav">
<div class="slide-nav__img slide-nav__img--prev" style="background-image:url(img/15.jpg);"></div>
<div class="slide-nav__img slide-nav__img--next" style="background-image:url(img/16.jpg);"></div>
</nav>
</div>
<div class="content__item" id="item-4">
<span class="content__item-number oh"><span class="oh__inner">04</span></span>
<h2 class="content__item-heading oh"><span class="oh__inner">Mechanism</span></h2>
<p class="content__item-text">
No matter how sophisticated, how cynical the public may become about publicity methods, it must respond to the basic appeals, because it will always need food, crave amusement, long for beauty, respond to leadership.
</p>
<a class="content__item-link oh"><span class="oh__inner">View more</span></a>
<nav class="slide-nav">
<div class="slide-nav__img slide-nav__img--prev" style="background-image:url(img/17.jpg);"></div>
<div class="slide-nav__img slide-nav__img--next" style="background-image:url(img/18.jpg);"></div>
</nav>
</div>
<div class="content__item" id="item-5">
<span class="content__item-number oh"><span class="oh__inner">05</span></span>
<h2 class="content__item-heading oh"><span class="oh__inner">Millions</span></h2>
<p class="content__item-text">
This practice of creating circumstances and of creating pictures in the minds of millions of persons is very common.
</p>
<a class="content__item-link oh"><span class="oh__inner">View more</span></a>
<nav class="slide-nav">
<div class="slide-nav__img slide-nav__img--prev" style="background-image:url(img/19.jpg);"></div>
<div class="slide-nav__img slide-nav__img--next" style="background-image:url(img/20.jpg);"></div>
</nav>
</div>
<div class="content__item" id="item-6">
<span class="content__item-number oh"><span class="oh__inner">06</span></span>
<h2 class="content__item-heading oh"><span class="oh__inner">Continuous</span></h2>
<p class="content__item-text">
The important thing is that it is universal and continuous; and in its sum total it is regimenting the public mind every bit as much as an army regiments the bodies of its soldiers.
</p>
<a class="content__item-link oh"><span class="oh__inner">View more</span></a>
<nav class="slide-nav">
<div class="slide-nav__img slide-nav__img--prev" style="background-image:url(img/21.jpg);"></div>
<div class="slide-nav__img slide-nav__img--next" style="background-image:url(img/22.jpg);"></div>
</nav>
</div>
<div class="content__item" id="item-7">
<span class="content__item-number oh"><span class="oh__inner">07</span></span>
<h2 class="content__item-heading oh"><span class="oh__inner">Irresistible</span></h2>
<p class="content__item-text">
When regimented, a group at times offers an irresistible pressure before which legislators, editors, and teachers are helpless.
</p>
<a class="content__item-link oh"><span class="oh__inner">View more</span></a>
<nav class="slide-nav">
<div class="slide-nav__img slide-nav__img--prev" style="background-image:url(img/29.jpg);"></div>
<div class="slide-nav__img slide-nav__img--next" style="background-image:url(img/30.jpg);"></div>
</nav>
</div>
<div class="content__item" id="item-8">
<span class="content__item-number oh"><span class="oh__inner">08</span></span>
<h2 class="content__item-heading oh"><span class="oh__inner">Pressure</span></h2>
<p class="content__item-text">
A desire for a specific reform, however widespread, cannot be translated into action until it is made articulate, and until it has exerted sufficient pressure upon the proper law-making bodies.
</p>
<a class="content__item-link oh"><span class="oh__inner">View more</span></a>
<nav class="slide-nav">
<div class="slide-nav__img slide-nav__img--prev" style="background-image:url(img/23.jpg);"></div>
<div class="slide-nav__img slide-nav__img--next" style="background-image:url(img/24.jpg);"></div>
</nav>
</div>
<div class="content__item" id="item-9">
<span class="content__item-number oh"><span class="oh__inner">09</span></span>
<h2 class="content__item-heading oh"><span class="oh__inner">Interests</span></h2>
<p class="content__item-text">
In the active proselytizing minorities in whom selfish interests and public interests coincide lie the progress and development of America.
</p>
<a class="content__item-link oh"><span class="oh__inner">View more</span></a>
<nav class="slide-nav">
<div class="slide-nav__img slide-nav__img--prev" style="background-image:url(img/25.jpg);"></div>
<div class="slide-nav__img slide-nav__img--next" style="background-image:url(img/26.jpg);"></div>
</nav>
</div>
<div class="content__item" id="item-10">
<span class="content__item-number oh"><span class="oh__inner">10</span></span>
<h2 class="content__item-heading oh"><span class="oh__inner">Think</span></h2>
<p class="content__item-text">
Small groups of persons can, and do, make the rest of us think what they please about a given subject.
</p>
<a class="content__item-link oh"><span class="oh__inner">View more</span></a>
<nav class="slide-nav">
<div class="slide-nav__img slide-nav__img--prev" style="background-image:url(img/27.jpg);"></div>
<div class="slide-nav__img slide-nav__img--next" style="background-image:url(img/28.jpg);"></div>
</nav>
</div>
<button class="back">
<svg viewBox="0 0 50 9" width="100%"><path d="M0 4.5l5-3M0 4.5l5 3M50 4.5h-77"></path></svg>
</button>
<nav class="grid grid--mini">
<div class="grid__cell grid__cell-c1-r1">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/1.jpg)"></div>
</div>
</div>
<div class="grid__cell grid__cell-c3-r1">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/2.jpg)"></div>
</div>
</div>
<div class="grid__cell grid__cell-c4-r1">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/3.jpg)"></div>
</div>
</div>
<div class="grid__cell grid__cell-c1-r2">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/4.jpg)"></div>
</div>
</div>
<div class="grid__cell grid__cell-c3-r2">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/5.jpg)"></div>
</div>
</div>
<div class="grid__cell grid__cell-c2-r3">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/6.jpg)"></div>
</div>
</div>
<div class="grid__cell grid__cell-c4-r3">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/7.jpg)"></div>
</div>
</div>
<div class="grid__cell grid__cell-c1-r4">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/8.jpg)"></div>
</div>
</div>
<div class="grid__cell grid__cell-c3-r4">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/9.jpg)"></div>
</div>
</div>
<div class="grid__cell grid__cell-c3-r5">
<div class="grid__cell-img">
<div class="grid__cell-img-inner" style="background-image:url(img/10.jpg)"></div>
</div>
</div>
</nav>
</div>
</main>
<!-- Excerpts from: Propaganda (1928) by Edward Bernays -->
<script type="module" src="js/index.js"></script>
</body>
</html>함께 쓰는 파일 10개 보기
src/js/contentItem.js
import { TextReveal } from './textReveal';
import { TextLinesReveal } from './textLinesReveal';
/**
* Class representing a content item (.content__item).
*/
export class ContentItem {
// DOM elements
DOM = {
// Main element (.content__item)
el: null
};
// TextReveal obj to animate the texts (slide in/out)
textReveal = null;
// TextLinesReveal obj to animate the ,ulti line texts (slide in/out)
textLinesReveal = null;
/**
* Constructor.
* @param {Element} DOM_el - the .content__item element.
*/
constructor(DOM_el) {
this.DOM.el = DOM_el;
this.DOM.nav = {
prev: this.DOM.el.querySelector('.slide-nav__img--prev'),
next: this.DOM.el.querySelector('.slide-nav__img--next')
};
// Text animations
this.textReveal = new TextReveal([...this.DOM.el.querySelectorAll('.oh')]);
// Text lines animations
this.textLinesReveal = new TextLinesReveal(this.DOM.el.querySelector('.content__item-text'));
}
}src/js/grid.js
import { ImageCell } from './imageCell';
import { calcWinsize, adjustedBoundingRect } from './utils';
import { TextReveal } from './textReveal';
import { gsap } from 'gsap';
// body element
const bodyEl = document.body;
// Calculate the viewport size
let winsize = calcWinsize();
window.addEventListener('resize', () => winsize = calcWinsize());
/**
* Class representing a grid of images, where the grid can be zoomed to the clicked image cell
*/
export class Grid {
// DOM elements
DOM = {
// main element (.grid)
el: null,
// .grid__cell-img elements
imageCells: null,
// content section
content: null,
// .back button
backCtrl: null,
// The mini grid shown in the content area
miniGrid: {
// main element
el: null,
// cells
cells: null
}
};
// ImageCell instances array
imageCellArr = [];
// Index of current imageCell
currentCell = -1;
// Checks if in view mode or if in content mode
isGridView = true;
// Checks for active animation
isAnimating = false;
// TextReveal obj to animate the texts (slide in/out)
textReveal = null;
/**
* Constructor.
* @param {Element} DOM_el - the .grid--large element
*/
constructor(DOM_el) {
this.DOM.el = DOM_el;
this.DOM.imageCells = [...this.DOM.el.querySelectorAll('.grid__cell-img')];
this.DOM.imageCells.forEach(el => this.imageCellArr.push(new ImageCell(el)));
this.DOM.content = document.querySelector('.content');
this.DOM.backCtrl = this.DOM.content.querySelector('.back');
this.DOM.miniGrid.el = this.DOM.content.querySelector('.grid--mini');
this.DOM.miniGrid.cells = [...this.DOM.miniGrid.el.querySelectorAll('.grid__cell')];
// Text animations
this.textReveal = new TextReveal([...this.DOM.el.querySelectorAll('.oh')]);
// Events
this.initEvents();
// Track which cells are visible
//this.trackVisibleCells();
}
/**
* Track which cells are visible (inside the viewport)
* by adding/removing the 'in-view' class when scrolling.
* This will be used to animate only the ones that are visible.
*/
trackVisibleCells() {
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.intersectionRatio > 0) {
entry.target.classList.add('in-view');
}
else {
entry.target.classList.remove('in-view');
}
});
});
this.DOM.imageCells.forEach(img => observer.observe(img));
}
/**
* Init/Bind events.
*/
initEvents() {
// for every imageCell
for (const [position,imageCell] of this.imageCellArr.entries()) {
// Open the imageCell and reveal its content
imageCell.DOM.el.addEventListener('click', () => {
if ( !this.isGridView || this.isAnimating ) {
return false;
}
this.isAnimating = true;
this.isGridView = false;
// Update the mini grid current cell
if ( this.currentCell !== -1 ) {
this.DOM.miniGrid.cells[this.currentCell].classList.remove('grid__cell--current');
}
// Update currentCell
this.currentCell = position;
this.DOM.miniGrid.cells[this.currentCell].classList.add('grid__cell--current');
this.showContent(imageCell);
});
// Hover on the image cell will scale down the outer element and scale up the inner element.
imageCell.DOM.el.addEventListener('mouseenter', () => {
if ( !this.isGridView ) {
return false;
}
gsap.killTweensOf([imageCell.DOM.el, imageCell.DOM.inner]);
gsap.timeline({
defaults: {duration: 2.4, ease: 'expo'}
})
.to(imageCell.DOM.el, {scale: 0.95}, 0)
.to(imageCell.DOM.inner, {scale: 1.4}, 0);
});
// Hovering out will reverse the scale values.
imageCell.DOM.el.addEventListener('mouseleave', () => {
if ( !this.isGridView ) {
return false;
}
gsap.killTweensOf([imageCell.DOM.el, imageCell.DOM.inner]);
gsap.timeline({
defaults: {duration: 2.4, ease: 'expo'}
})
.to([imageCell.DOM.el, imageCell.DOM.inner], {scale: 1}, 0);
});
}
// Close the imageCell and reveal the grid
this.DOM.backCtrl.addEventListener('click', () => {
if ( this.isAnimating ) {
return false;
}
this.isAnimating = true;
this.isGridView = true;
this.closeContent();
});
this.DOM.miniGrid.cells.forEach((cell, position) => {
cell.addEventListener('click', () => {
if ( this.isAnimating || this.currentCell === position ) {
return false;
}
this.isAnimating = true;
this.changeContent(position);
});
});
// Recalculate current image transform
window.addEventListener('resize', () => {
if ( this.isGridView ) {
return false;
}
// Calculate the transform to apply to the image cell
const imageTransform = this.calcTransformImage();
gsap.set(this.imageCellArr[this.currentCell].DOM.el, {
scale: imageTransform.scale,
x: imageTransform.x,
y: imageTransform.y
});
});
}
/**
* Scale up the image and reveal its content.
* @param {ImageCell} imageCell - the imageCell element.
*/
showContent(imageCell) {
// Calculate the transform to apply to the image cell
const imageTransform = this.calcTransformImage();
// All the others (that are inside the viewport)
//this.otherImageCells = this.DOM.imageCells.filter(el => el != imageCell.DOM.el && el.classList.contains('in-view'));
this.otherImageCells = this.DOM.imageCells.filter(el => el != imageCell.DOM.el);
gsap.killTweensOf([imageCell.DOM.el, imageCell.DOM.inner, this.otherImageCells]);
gsap.timeline({
defaults: {
duration: 1.2,
ease: 'expo.inOut'
},
// overflow hidden
onStart: () => bodyEl.classList.add('oh'),
onComplete: () => {
this.isAnimating = false;
}
})
.addLabel('start', 0)
.add(() => {
// Hide grid texts
this.textReveal.out();
}, 'start')
.set(this.DOM.el, {
pointerEvents: 'none'
}, 'start')
.set(imageCell.DOM.el, {
zIndex: 100
}, 'start')
.set([imageCell.DOM.el, imageCell.DOM.inner, this.otherImageCells], {
willChange: 'transform, opacity'
}, 'start')
.to(imageCell.DOM.el, {
scale: imageTransform.scale,
x: imageTransform.x,
y: imageTransform.y,
onComplete: () => gsap.set(imageCell.DOM.el, {willChange: ''})
}, 'start')
.to(imageCell.DOM.inner, {
scale: 1,
onComplete: () => gsap.set(imageCell.DOM.inner, {willChange: ''})
}, 'start')
.to([imageCell.contentItem.DOM.nav.prev, imageCell.contentItem.DOM.nav.next], {
y: 0
}, 'start')
.to(this.otherImageCells, {
opacity: 0,
scale: 0.8,
onComplete: () => gsap.set(this.otherImageCells, {willChange: ''}),
stagger: {
grid: 'auto',
amount: 0.17,
from: this.currentCell
}
}, 'start')
.addLabel('showContent', 'start+=0.45')
.to(this.DOM.backCtrl, {
ease: 'expo',
startAt: {x: '50%'},
x: '0%',
opacity: 1
}, 'showContent')
.set(this.DOM.miniGrid.el, {
opacity: 1
}, 'showContent')
.set(this.DOM.miniGrid.cells, {
opacity: 0
}, 'showContent')
.to(this.DOM.miniGrid.cells, {
duration: 1,
ease: 'expo',
opacity: 1,
startAt: {scale: 0.8},
scale: 1,
stagger: {
grid: 'auto',
amount: 0.3,
from: this.currentCell
}
}, 'showContent+=0.2')
.add(() => {
imageCell.contentItem.textReveal.in();
imageCell.contentItem.textLinesReveal.in();
this.DOM.content.classList.add('content--open');
}, 'showContent')
.add(() => imageCell.contentItem.DOM.el.classList.add('content__item--current'), 'showContent+=0.02');
}
/**
* Scale down the image and reveal the grid again.
*/
closeContent() {
// Current imageCell
const imageCell = this.imageCellArr[this.currentCell];
this.otherImageCells = this.DOM.imageCells.filter(el => el != imageCell.DOM.el);
gsap.timeline({
defaults: {
duration: 1,
ease: 'expo.inOut'
},
// overflow hidden
onStart: () => bodyEl.classList.remove('oh'),
onComplete: () => {
this.isAnimating = false;
}
})
.addLabel('start', 0)
.to(this.DOM.backCtrl, {
x: '50%',
opacity: 0
}, 'start')
.to(this.DOM.miniGrid.cells, {
duration: 0.5,
ease: 'expo.in',
opacity: 0,
scale: 0.8,
stagger: {
grid: 'auto',
amount: 0.1,
from: -this.currentCell
},
onComplete: () => {
gsap.set(this.DOM.miniGrid.el, {
opacity: 0
})
}
}, 'start')
.add(() => {
imageCell.contentItem.textReveal.out();
imageCell.contentItem.textLinesReveal.out();
this.DOM.content.classList.remove('content--open');
}, 'start')
.add(() => imageCell.contentItem.DOM.el.classList.remove('content__item--current'))
.addLabel('showGrid', 0)
.set([imageCell.DOM.el, this.otherImageCells], {
willChange: 'transform, opacity'
}, 'showGrid')
.to(imageCell.DOM.el, {
scale: 1,
x: 0,
y: 0,
onComplete: () => gsap.set(imageCell.DOM.el, {willChange: '', zIndex: 1})
}, 'showGrid')
.to(imageCell.contentItem.DOM.nav.prev, {
y: '-100%'
}, 'showGrid')
.to(imageCell.contentItem.DOM.nav.next, {
y: '100%'
}, 'showGrid')
.to(this.otherImageCells, {
opacity: 1,
scale: 1,
onComplete: () => {
gsap.set(this.otherImageCells, {willChange: ''});
gsap.set(this.DOM.el, { pointerEvents: 'auto' });
},
stagger: {
grid: 'auto',
amount: 0.17,
from: -this.currentCell
}
}, 'showGrid')
.add(() => {
// Show grid texts
this.textReveal.in();
}, 'showGrid+=0.3')
}
/**
*
*/
changeContent(position) {
// Current imageCell
const imageCell = this.imageCellArr[this.currentCell];
// Upcoming imageCell
const upcomingImageCell = this.imageCellArr[position];
this.DOM.miniGrid.cells[this.currentCell].classList.remove('grid__cell--current');
this.currentCell = position;
this.DOM.miniGrid.cells[this.currentCell].classList.add('grid__cell--current');
// Calculate the transform to apply to the image cell
const imageTransform = this.calcTransformImage();
gsap.timeline({
defaults: {
duration: 1,
ease: 'expo.inOut'
},
onComplete: () => {
this.isAnimating = false;
}
})
.addLabel('start', 0)
.add(imageCell.contentItem.textReveal.out(), 'start')
.add(imageCell.contentItem.textLinesReveal.out(), 'start')
.add(() => {
imageCell.contentItem.DOM.el.classList.remove('content__item--current');
})
.set([imageCell.DOM.el, upcomingImageCell.DOM.el], {
willChange: 'transform, opacity'
}, 'start')
.to(imageCell.DOM.el, {
opacity: 0,
scale: 0.8,
x: 0,
y: 0,
onComplete: () => gsap.set(imageCell.DOM.el, {willChange: '', zIndex: 1})
}, 'start')
.to(imageCell.contentItem.DOM.nav.prev, {
y: '-100%'
}, 'start')
.to(imageCell.contentItem.DOM.nav.next, {
y: '100%'
}, 'start')
.addLabel('showContent', '>-=0.4')
.set(upcomingImageCell.DOM.el, {
zIndex: 100
}, 'start')
.to(upcomingImageCell.DOM.el, {
scale: imageTransform.scale,
x: imageTransform.x,
y: imageTransform.y,
opacity: 1,
onComplete: () => gsap.set(upcomingImageCell.DOM.el, {willChange: ''})
}, 'start')
.to([upcomingImageCell.contentItem.DOM.nav.prev, upcomingImageCell.contentItem.DOM.nav.next], {
ease: 'expo',
y: 0
}, 'showContent')
.add(() => {
upcomingImageCell.contentItem.textReveal.in();
upcomingImageCell.contentItem.textLinesReveal.in();
}, 'showContent')
.add(() => {
upcomingImageCell.contentItem.DOM.el.classList.add('content__item--current');
}, 'showContent+=0.02');
}
/**
* Calculates the scale and translation values to apply to the image cell when we click on it.
* Also used to recalculate those values on resize.
* @return {JSON} the translation and scale values
*/
calcTransformImage() {
const cellrect = adjustedBoundingRect(this.imageCellArr[this.currentCell].DOM.el);
return {
scale: winsize.width * 0.54 / cellrect.width,
x: winsize.width * 0.65 - (cellrect.left + cellrect.width/2),
y: winsize.height * 0.50 - (cellrect.top + cellrect.height/2)
};
}
}src/js/imageCell.js
import { ContentItem } from './contentItem';
/**
* Class representing a image cell (.grid__cell-img).
*/
export class ImageCell {
// DOM elements
DOM = {
// Main element (.grid__cell-img)
el: null,
// Inner element
inner: null,
// The ImageCell's content item id.
contentId: null,
// The ContentItem instance
contentItem: null
};
/**
* Constructor.
* @param {Element} DOM_el - the .grid__cell-img element.
*/
constructor(DOM_el) {
this.DOM.el = DOM_el;
this.DOM.inner = this.DOM.el.querySelector('.grid__cell-img-inner');
// The ImageCell's content item id.
this.contentId = this.DOM.inner.dataset.item;
// The ContentItem instance
this.contentItem = new ContentItem(document.querySelector(`#${this.contentId}`));
}
}src/js/index.js
import { preloadImages } from './utils';
import { Grid } from './grid';
// Initialize the grid
new Grid(document.querySelector('.grid--large'));
// Preload images then remove loader (loading class) from body
preloadImages('.grid__cell-img-inner, .slide-nav__img').then(() => document.body.classList.remove('loading'));src/js/textLinesReveal.js
import SplitType from 'split-type';
import { wrapLines } from './utils';
import { gsap } from 'gsap';
export class TextLinesReveal {
constructor(animationElems) {
this.DOM = {
animationElems: Array.isArray(animationElems) ? animationElems : [animationElems]
};
// array of SplitType instances
this.SplitTypeInstances = [];
// array of all HTML .line
this.lines = [];
for (const el of this.DOM.animationElems) {
const SplitTypeInstance = new SplitType(el, { types: 'lines' });
// wrap the lines (div with class .oh)
// the inner child will be the one animating the transform
wrapLines(SplitTypeInstance.lines, 'div', 'oh');
this.lines.push(SplitTypeInstance.lines);
// keep a reference to the SplitType instance
this.SplitTypeInstances.push(SplitTypeInstance);
}
this.initEvents();
}
in() {
// lines are visible
this.isVisible = true;
// animation
gsap.killTweensOf(this.lines);
return gsap.timeline({defaults: {duration: 1.2, ease: 'expo'}})
.set(this.lines, {
y: '150%',
rotate: 15
})
.to(this.lines, {
y: '0%',
rotate: 0,
stagger: 0.04
});
}
out() {
// lines are invisible
this.isVisible = false;
// animation
gsap.killTweensOf(this.lines);
return gsap.timeline({
defaults: {duration: 0.5, ease: 'expo.in'}
})
.to(this.lines, {
y: '-150%',
rotate: -5,
stagger: 0.02
});
}
initEvents() {
window.addEventListener('resize', () => {
// empty the lines array
this.lines = [];
// re initialize the Split Text
for (const instance of this.SplitTypeInstances) {
// re-split text
// https://github.com/lukePeavey/SplitType#instancesplitoptions-void
instance.split();
// need to wrap again the new lines elements (div with class .oh)
wrapLines(instance.lines, 'div', 'oh');
this.lines.push(instance.lines);
}
// hide the lines
if ( !this.isVisible ) {
gsap.set(this.lines, {y: '-150%'});
}
});
}
}src/js/textReveal.js
import { gsap } from 'gsap';
export class TextReveal {
constructor(el) {
this.DOM = {
outer: el,
inner: Array.isArray(el) ? el.map(outer => outer.querySelector('.oh__inner')) : el.querySelector('.oh__inner')
}
}
in() {
if ( this.outTimeline && this.outTimeline.isActive() ) {
this.outTimeline.kill();
}
this.inTimeline = gsap.timeline({defaults: {duration: 1.2, ease: 'expo'}})
.set(this.DOM.inner, {
y: '120%',
rotate: 15
})
.to(this.DOM.inner, {
y: '0%',
rotate: 0,
stagger: 0.03
});
return this.inTimeline;
}
out() {
if ( this.inTimeline && this.inTimeline.isActive() ) {
this.inTimeline.kill();
}
this.outTimeline = gsap.timeline({defaults: {duration: 0.5, ease: 'expo.in'}})
.to(this.DOM.inner, {
y: '-120%',
rotate: -5,
stagger: 0.03
});
return this.outTimeline;
}
}src/js/utils.js
const imagesLoaded = require('imagesloaded');
// Preload images
const preloadImages = (selector = 'img') => {
return new Promise((resolve) => {
imagesLoaded(document.querySelectorAll(selector), {background: true}, resolve);
});
};
const calcWinsize = () => {
return { width: window.innerWidth, height: window.innerHeight };
};
const getScrollValues = () => {
const supportPageOffset = window.pageXOffset !== undefined;
const isCSS1Compat = ((document.compatMode || "") === "CSS1Compat");
const x = supportPageOffset ? window.pageXOffset : isCSS1Compat ? document.documentElement.scrollLeft : document.body.scrollLeft;
const y = supportPageOffset ? window.pageYOffset : isCSS1Compat ? document.documentElement.scrollTop : document.body.scrollTop;
return {x,y};
}
// wrap each element of an array
// elems - the array of elements to wrap
// wrapType - type of wrapper ('div', 'span' etc)
// wrapClass - wrapper class(s)
const wrapLines = (elems, wrapType, wrapClass) => {
elems.forEach(char => {
// add a wrap for every char (overflow hidden)
const wrapEl = document.createElement(wrapType);
wrapEl.classList = wrapClass;
char.parentNode.appendChild(wrapEl);
wrapEl.appendChild(char);
});
}
const adjustedBoundingRect = el => {
var rect = el.getBoundingClientRect();
var style = getComputedStyle(el);
var tx = style.transform;
if (tx) {
var sx, sy, dx, dy;
if (tx.startsWith('matrix3d(')) {
var ta = tx.slice(9,-1).split(/, /);
sx = +ta[0];
sy = +ta[5];
dx = +ta[12];
dy = +ta[13];
} else if (tx.startsWith('matrix(')) {
var ta = tx.slice(7,-1).split(/, /);
sx = +ta[0];
sy = +ta[3];
dx = +ta[4];
dy = +ta[5];
} else {
return rect;
}
var to = style.transformOrigin;
var x = rect.x - dx - (1 - sx) * parseFloat(to);
var y = rect.y - dy - (1 - sy) * parseFloat(to.slice(to.indexOf(' ') + 1));
var w = sx ? rect.width / sx : el.offsetWidth;
var h = sy ? rect.height / sy : el.offsetHeight;
return {
x: x, y: y, width: w, height: h, top: y, right: x + w, bottom: y + h, left: x
};
} else {
return rect;
}
}
export {
preloadImages,
calcWinsize,
getScrollValues,
wrapLines,
adjustedBoundingRect
};Media credits and license evidence실행 안내·자료
README.md
## Credits
- Images from [Unsplash](https://unsplash.com/)
## License
[MIT](LICENSE)
Made with :blue_heart: by [Codrops](http://www.codrops.com)
LICENSE실행 안내·자료
MIT License
Copyright (c) 2009 - 2021 [Codrops](https://tympanus.net/codrops)
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.
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
이 장면을 만드는 원리
확대 이미지 목적지는 뷰포트 비율로 정함
화면 크기·입력·동시 작업을 고정하고 실제 렌더링 실패와 비용을 관찰합니다.
- 이 예제에서는
- calcTransformImage는 원래 셀 사각형에서 화면 폭 54%의 크기와 x=65%, y=50% 중심까지의 변환을 구합니다. 주변 정보의 자리와 함께 검증할 제품 값입니다.
