Installation : 둘 중에 하나를 설치해 줍니다
npm install react-slick --save
yarn add react-slick
Include css
-> 내장되어 있는 css 설치를 하고
npm install slick-carousel --save
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";
-> 사용할 컴포넌트 부분에 import 해줍니다
Slick API
const setting ={
slide: 'div',
infinite : true,
slidesToShow : 4,
slidesToScroll : 1,
speed : 100,
arrows : true,
dots : true,
autoplay : true,
autoplaySpeed : 10000,
pauseOnHover : true,
vertical : false,
prevArrow : "<button type='button' class='slick-prev'>Previous</button>",
nextArrow : "<button type='button' class='slick-next'>Next</button>",
dotsClass : "slick-dots",
draggable : true,
responsive: [
{
breakpoint: 960,
settings: {
slidesToShow:3
}
},
{
breakpoint: 768,
settings: {
slidesToShow:2
}
}
]
}
ex) react
import Slider from "react-slick";
import "./Slick.css";
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";
function Slick() {
const settings = {
dots: false,
infinite: false,
speed: 500,
slidesToShow: 3,
slidesToScroll: 1,
arrows: true,
};
return (
<div className="container">
<Slider {...settings}>
<div>
<img src="man.jpg" alt="" />
</div>
<div>
<img src="man2.jpg" alt="" />
</div>
<div>
<img src="woman.jpg" alt="" />
</div>
<div>
<img src="woman2.jpg" alt="" />
</div>
</Slider>
</div>
);
}
ex)css : slider 태그 안에 있는 태그는 .slice-slice 뒤에 사용
body {
background-color: #05486e;
}
.container {
width: 90%;
height: 500px;
margin: 5%;
}
.slick-slide {
height: 320px;
border: 20px solid #05486e;
box-sizing: border-box;
}
.slick-slide img {
object-fit: cover;
height: 500px;
width: 100%;
box-sizing: border-box;
}