Notice
Recent Posts
Recent Comments
Link
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 깃 토큰 만료
- 중복단어제거
- 제로베이스
- 문자열순서바꾸기
- 중복문자제거
- 문자열 중복
- 레디스 확인
- 코딩 어?
- 프론트엔드 스쿨
- 우분투 시간 변경
- 중첩배열평탄화
- 중첩배열
- 스프링 데이타 JPA
- @Moditying @Query
- 배엘에서 스왑
- ...점점점문법
- 중복 문자열
- ubuntu타임존
- 아래로펼치기
- 시퀄 문법
- sql 문자열 패턴 검색
- 재귀스왑
- lastIndexOf()
- 중복된 단어
- js 문자열을 문자배열로
- 5.3.8 Modifying Queries
- 객체의키값만 찾기
- 객체의 밸류값만 찾기
- indexOf()
- 단어 제거
Archives
- Today
- Total
코딩기록
Carousel) Swiper(스와이퍼)- 반응형 슬라이드(캐러셀) 라이브러리 본문
728x90
Swiper(스와이퍼)는 반응형 슬라이드(캐러셀) 라이브러리로, 이미지 슬라이더나 배너 캐러셀 등을 만들 때 많이 사용.
React 프로젝트 기준.
✅ 1단계: Swiper 설치
npm install swiper
✅ 2단계: 스타일 불러오기
globals.css 또는 layout.tsx에서 전역 스타일에 추가.
// 예: app/globals.css
@import 'swiper/css';
@import 'swiper/css/navigation';
@import 'swiper/css/pagination';
✅ 3단계: 사용 예시 (React 컴포넌트)
"use client"; // Next.js App Router 사용 시 필수
import { Swiper, SwiperSlide } from "swiper/react";
import { Navigation, Pagination, Autoplay } from "swiper/modules";
import "swiper/css";
import "swiper/css/navigation";
import "swiper/css/pagination";
const BannerCarousel = () => {
return (
<Swiper
modules={[Navigation, Pagination, Autoplay]}
spaceBetween={30} // 슬라이드 간 간격 (px)
slidesPerView={1} // 한 화면에 보일 슬라이드 수
navigation // 자동 재생 설정
pagination={{ clickable: true }} // 페이지 점 표시 설정
autoplay={{ delay: 3000, disableOnInteraction: false }} // 자동 재생 설정
loop // 슬라이드 반복 여부
className="w-full h-64" // Tailwind로 크기 조절
>
<SwiperSlide>
<img src="/images/banner1.jpg" alt="배너1" className="w-full h-full object-cover rounded-lg" />
</SwiperSlide>
<SwiperSlide>
<img src="/images/banner2.jpg" alt="배너2" className="w-full h-full object-cover rounded-lg" />
</SwiperSlide>
<SwiperSlide>
<img src="/images/banner3.jpg" alt="배너3" className="w-full h-full object-cover rounded-lg" />
</SwiperSlide>
</Swiper>
);
};
export default BannerCarousel;
✅ 4단계: 옵션 설명
옵션 설명
slidesPerView | 한 화면에 보일 슬라이드 수 |
spaceBetween | 슬라이드 간 간격 (px) |
loop | 슬라이드 반복 여부 |
autoplay | 자동 재생 설정 |
navigation | 이전/다음 버튼 표시 |
pagination | 페이지 점 표시 설정 |
✅ 5단계: CSS 커스터마이징 (선택)
/* Swiper navigation 버튼 크기 조절 예시 */
.swiper-button-next,
.swiper-button-prev {
color: #333;
scale: 1.2;
}
참고
쳇지피티
반응형
'프론트 > 리액트' 카테고리의 다른 글
색상에 따라 텍스트 배경 바꾸기 (0) | 2025.06.20 |
---|---|
Next.js) 폴더명에 []대괄호 사용- 동적라우팅 (1) | 2025.06.20 |
문법) 'use client'를 작성하는 이유- 서버 컴포넌트, 클라이언트 컴포넌트 (0) | 2025.06.11 |
반복되는 JSX 문법 .map으로 간략하게 (3) | 2025.06.10 |
css) input 포커스 시 움직임 수정 (0) | 2025.06.09 |
Comments