01基本scroll-snap
4枚の写真カードを横に並べ、指やホイールで動かすとカードが画面にぴったり収まる位置で止まる。overflow-x:autoとscroll-snap-typeの2つだけで動き、JSは1行もない。
使いどころECサイトの商品ギャラリー、ポートフォリオの作品めくり
scroll-snap-typescroll-snap-alignJS 0줄

<main class="stage">
<div class="cs is-demo">
<div class="cs__viewport">
<div class="cs__track">
<div class="cs__slide cs__slide--1"><span class="cs__cap">新作コレクション</span></div>
<div class="cs__slide cs__slide--2"><span class="cs__cap">ベストセラーTOP</span></div>
<div class="cs__slide cs__slide--3"><span class="cs__cap">送料無料イベント</span></div>
<div class="cs__slide cs__slide--4"><span class="cs__cap">お客様の声</span></div>
<div class="cs__slide cs__slide--1" aria-hidden="true"><span class="cs__cap">新作コレクション</span></div>
</div>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// ── 변수 3개 ──────────────────────────────────────────
$duration: $dur-base; // 데모 자동 재생 한 칸 이동 시간
$easing: $ease-spring;
$color: $subject-blue; // 슬라이드 1 색
@include stage($stage-ink);
.cs { width: min(400px, 92vw); overflow: hidden; border-radius: $r-card; }
// ── 실제 동작: overflow-x:auto + scroll-snap-type 만으로 끝난다 (0줄 JS) ──
// .cs__viewport 가 진짜 스크롤 상자. .cs__track 은 그 안의 콘텐츠(슬라이드 4장 = 400%)일 뿐이라
// 데모 루프가 track 을 옮겨도 실제 스크롤 위치·스냅은 그대로 살아있다
.cs__viewport {
overflow-x: auto;
scroll-snap-type: x mandatory;
-webkit-overflow-scrolling: touch;
scrollbar-width: none;
&::-webkit-scrollbar { display: none; }
}
// ── 무한 루프 이음새: 첫 슬라이드를 트랙 끝에 한 장 더 복제해 둔다 ──
// 마지막→처음 되돌아감이 순간이동으로 보이지 않게, 예고편은 복제본까지 "다음 칸"처럼 한 칸 더 가고
// 100%→0% 재시작은 복제본이 1번과 똑같이 생겨 눈에 보이지 않는다 (끝→처음 텔레포트 금지, 사용자 2026-09-11)
.cs__track {
display: flex;
width: 500%;
}
.cs__slide {
flex: 0 0 20%;
scroll-snap-align: start;
aspect-ratio: 16 / 9;
margin-right: $sp-3;
border-radius: $r-card;
position: relative;
overflow: hidden;
display: grid;
place-items: end start;
box-sizing: border-box;
}
.cs__slide:last-child { margin-right: 0; }
// 플레이스홀더 "사진" — 해·산 모양을 순수 CSS 로 (외부 이미지 0)
.cs__slide::before {
content: ""; position: absolute; top: $sp-4; right: $sp-4;
width: $sp-10; height: $sp-10; border-radius: 50%;
background: rgba(255, 255, 255, .85);
}
.cs__slide::after {
content: ""; position: absolute; left: -8%; right: -8%; bottom: -6%; height: 52%;
background: rgba(23, 20, 26, .28);
clip-path: polygon(0% 100%, 20% 38%, 40% 64%, 58% 24%, 76% 58%, 100% 32%, 100% 100%);
}
.cs__slide--1 { background: linear-gradient(135deg, $color, #d6ddeb); }
.cs__slide--2 { background: linear-gradient(135deg, $stage-orange, #ebdbd6); }
.cs__slide--3 { background: linear-gradient(135deg, #c2ae82, $stage-yellow); }
.cs__slide--4 { background: linear-gradient(135deg, $subject-ink, #4a3f5c); }
.cs__cap {
position: relative; z-index: 1;
margin: $sp-4;
padding: $sp-1 $sp-3;
border-radius: $r-pill;
background: rgba(23, 20, 26, .38);
color: $subject-cream;
font-weight: 600;
font-size: clamp(12px, 3.2vw, 14px);
line-height: 1;
font-family: inherit;
}
// ── 데모 루프: 클릭·드래그 전까지 한 칸씩 스스로 넘어간다 (진짜 스크롤은 그대로 살아있다) ──
// 마지막 칸은 1번의 복제본 — 거기까지 정상 속도로 가고 100%→0% 점프는 복제본=1번이라 안 보인다.
// 이동폭의 %는 트랙(500%) 기준이라 한 칸은 -20%, 슬라이드 사이 $sp-3 간격만큼 px 를 함께 뺀다
.cs.is-demo .cs__track { animation: cs-loop $dur-loop $easing infinite; }
@keyframes cs-loop {
0%, 8% { transform: translateX(0%); }
23%, 31% { transform: translateX(calc(-20% - #{$sp-3})); }
46%, 54% { transform: translateX(calc(-40% - #{$sp-3 * 2})); }
69%, 77% { transform: translateX(calc(-60% - #{$sp-3 * 3})); }
92%, 100% { transform: translateX(calc(-80% - #{$sp-3 * 4})); }
}
// ── 접근성 ──────────────────────────────────────────
@media (prefers-reduced-motion: reduce) {
.cs.is-demo .cs__track { animation: none !important; }
.cs__viewport { scroll-behavior: auto; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #17141a;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.cs {
width: min(400px, 92vw);
overflow: hidden;
border-radius: 16px;
}
.cs__viewport {
overflow-x: auto;
scroll-snap-type: x mandatory;
-webkit-overflow-scrolling: touch;
scrollbar-width: none;
}
.cs__viewport::-webkit-scrollbar {
display: none;
}
.cs__track {
display: flex;
width: 500%;
}
.cs__slide {
flex: 0 0 20%;
scroll-snap-align: start;
aspect-ratio: 16/9;
margin-right: 12px;
border-radius: 16px;
position: relative;
overflow: hidden;
display: grid;
place-items: end start;
box-sizing: border-box;
}
.cs__slide:last-child {
margin-right: 0;
}
.cs__slide::before {
content: "";
position: absolute;
top: 16px;
right: 16px;
width: 40px;
height: 40px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.85);
}
.cs__slide::after {
content: "";
position: absolute;
left: -8%;
right: -8%;
bottom: -6%;
height: 52%;
background: rgba(23, 20, 26, 0.28);
clip-path: polygon(0% 100%, 20% 38%, 40% 64%, 58% 24%, 76% 58%, 100% 32%, 100% 100%);
}
.cs__slide--1 {
background: linear-gradient(135deg, #2f6df6, #d6ddeb);
}
.cs__slide--2 {
background: linear-gradient(135deg, #ff4d1f, #ebdbd6);
}
.cs__slide--3 {
background: linear-gradient(135deg, #c2ae82, #ffd23f);
}
.cs__slide--4 {
background: linear-gradient(135deg, #17141a, #4a3f5c);
}
.cs__cap {
position: relative;
z-index: 1;
margin: 16px;
padding: 4px 12px;
border-radius: 999px;
background: rgba(23, 20, 26, 0.38);
color: #fff7e6;
font-weight: 600;
font-size: clamp(12px, 3.2vw, 14px);
line-height: 1;
font-family: inherit;
}
.cs.is-demo .cs__track {
animation: cs-loop 2s cubic-bezier(0.2, 0.8, 0.2, 1) infinite;
}
@keyframes cs-loop {
0%, 8% {
transform: translateX(0%);
}
23%, 31% {
transform: translateX(calc(-20% - 12px));
}
46%, 54% {
transform: translateX(calc(-40% - 24px));
}
69%, 77% {
transform: translateX(calc(-60% - 36px));
}
92%, 100% {
transform: translateX(calc(-80% - 48px));
}
}
@media (prefers-reduced-motion: reduce) {
.cs.is-demo .cs__track {
animation: none !important;
}
.cs__viewport {
scroll-behavior: auto;
}
}// 실제 동작은 overflow-x:auto + scroll-snap-type 만으로 이미 끝난다(0줄).
// 이 3줄은 미리보기가 스스로 도는 걸 멈추는 용도일 뿐 — 진짜 드래그·스크롤은 그대로 살아있다.
document.querySelector('.cs__viewport').addEventListener('pointerdown', function () {
document.querySelector('.cs').classList.remove('is-demo');
});import type { CSSProperties } from "react";
import styles from "./SnapBasic.module.scss";
const SLIDES = ["신상 컬렉션", "베스트셀러 TOP", "무료 배송 이벤트", "고객 후기"];
export type SnapBasicProps = {
duration?: number;
easing?: string;
color?: string;
};
type Vars = CSSProperties & { "--duration"?: string; "--easing"?: string; "--color"?: string };
export default function SnapBasic({ duration = 300, easing = "cubic-bezier(.2,.8,.2,1)", color = "#2f6df6" }: SnapBasicProps) {
const vars: Vars = { "--duration": `${duration}ms`, "--easing": easing, "--color": color };
return (
<div className={styles.cs} style={vars}>
{/* 실제 동작은 overflow-x:auto + scroll-snap-type 만으로 끝난다 — 드래그해서 넘기면 된다 */}
<div className={styles.viewport}>
<div className={styles.track}>
{SLIDES.map((label, i) => (
<div key={label} className={`${styles.slide} ${styles["slide" + (i + 1)]}`}>
<span className={styles.cap}>{label}</span>
</div>
))}
</div>
</div>
</div>
);
}01 基本scroll-snap — 計測 累積面積 62.372% · 動いたフレーム 19/23GODRICH オリジナル · SCSS と React は zip に同梱 · css 画像スライダー9選 — コピペで使えるカルーセル
このデモが属する記事
css 画像スライダー9選 — コピペで使えるカルーセル通販サイトの商品写真や会社サイトのトップ画像で、指でなぞったりボタンを押したりすると次の一枚に切り替わる仕組みを画像スライダーと呼びます。ここで紹介するcss 画像スライダーはCSSだけ・JS不要で、9種類のやり方をそのままコピペできる形に この記事のデモをすべて見る


