설치
npm install swiper/react
예시 코드
"use client";
import { styled } from "@mui/material";
import { Swiper, SwiperSlide } from "swiper/react";
import { Pagination } from "swiper/modules";
import "swiper/swiper-bundle.css";
const images = [
"/img/main-banner1.png",
"/img/main-banner1.png",
"/img/main-banner1.png",
];
const Carousel = () => {
return (
<div>
<Swiper
direction="horizontal" // 수직 방향
spaceBetween={50}
slidesPerView={1}
pagination={{ clickable: true }}
modules={[Pagination]}
style={{ height: "375px", width: "100%", backgroundColor:"red" }} // 원하는 크기로 조정
>
{images.map((src, index) => (
<SwiperSlide key={index}>
<Image src={src} alt={`Slide ${index + 1}`} />
</SwiperSlide>
))}
</Swiper>
</div>
);
};
export default Carousel;
const Image = styled("img")`
width: 100%;
height: 100%;
object-fit: cover;
`;
'프론트엔드 > Component' 카테고리의 다른 글
[Component] MUI 아코디언 컴포넌트 예시 코드 (0) | 2025.03.04 |
---|---|
[Component] 아코디언 배열 렌더링을 위한 재사용 컴포넌트 예시 코드 (0) | 2025.03.04 |
[Component] 2단 사이드바 컴포넌트(MUI + styled-components + Zustand) (1) | 2024.12.26 |
[Component] 사이드바 컴포넌트(MUI + styled-components + Zustand) (0) | 2024.12.26 |
[Component] 전역 모달 컴포넌트 (0) | 2024.12.18 |