slick
jQuery ๊ธฐ๋ฐ ์ด๋ฏธ์ง ์ฌ๋ผ์ด๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
1.
slick ํ๋ฌ๊ทธ์ธ ๊ฐ์ ธ์ค๊ธฐ
a.
CDN ์ผ๋ก ๊ฐ์ ธ์ค๊ธฐ
<!-- slick css CDN -->
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css"/>
<!-- slick js CDN -->
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js"></script>
HTML
๋ณต์ฌ
2.
jQuery ๊ฐ์ ธ์ค๊ธฐ
<!-- jQuery CDN ๋ฐฉ์์ผ๋ก ํฌํจํ๊ธฐ -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
HTML
๋ณต์ฌ
jQuery ํฌํจํ๋ ์ฝ๋๊ฐ ํ๋ฌ๊ทธ์ธ ํฌํจ์ฝ๋๋ณด๋ค ์์ ์์ด์ผํ๋ค.
3.
๋ด๊ฐ ๋ง๋ css / script ๊ฐ์ ธ์ค๊ธฐ
<link rel="stylesheet" href="css/style.css">
<script src="js/script.js"></script>
HTML
๋ณต์ฌ
4.
์์ ๋ด์ฉ์ ํ ๋ฒ ํฌํจํ๊ธฐ
<!-- slick ํ๋ฌ๊ทธ์ธ -->
<!-- slick css CDN -->
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css"/>
<!-- slick css FILE -->
<link rel="stylesheet" href="css/slick.css">
<link rel="stylesheet" href="css/slick-theme.css">
<!-- css -->
<link rel="stylesheet" href="css/style.css">
<!-- jQuery CDN -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<!-- slick js CDN -->
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js"></script>
<!-- slick js FILE -->
<script src="js/slick.min.js"></script>
<!-- js -->
<script src="js/script.js"></script>
HTML
๋ณต์ฌ
5.
์ด๋ฏธ์ง ์ฌ๋ผ์ด๋ HTML ์ฝ๋ ์์ฑ
<div class="slide-container">
<div class="slide"><img src="img/slide01.jpg" alt=""></div>
<div class="slide"><img src="img/slide02.jpg" alt=""></div>
<div class="slide"><img src="img/slide03.jpg" alt=""></div>
<div class="slide"><img src="img/slide04.jpg" alt=""></div>
<div class="slide"><img src="img/slide05.jpg" alt=""></div>
<div class="slide"><img src="img/slide06.jpg" alt=""></div>
<div class="slide"><img src="img/slide07.jpg" alt=""></div>
<div class="slide"><img src="img/slide08.jpg" alt=""></div>
<div class="slide"><img src="img/slide09.jpg" alt=""></div>
</div>
HTML
๋ณต์ฌ
6.
๊ธฐ๋ณธ ์คํ์ผ ์ง์ ํ๊ธฐ
.slide-container {
width: 1200px;
height: 480px;
margin: 150px auto;
}
.slide {
width: auto;
height: 480px;
padding: 20px;
box-sizing: border-box;
}
.slide img {
width: 100%;
height: 100%;
}
CSS
๋ณต์ฌ
7.
์ฌ๋ผ์ด๋ ์์ญ ๋ฐ์ํ ์ ์ฉํ๊ธฐ
/* ๋ฐ์ํ */
@media screen and (max-width: 1024px) {
.slide-container { width: 800px; }
}
@media screen and (max-width: 800px) {
.slide-container { width: 500px; height: 300px; }
.slide { height: 300px; }
}
@media screen and (max-width: 480px) {
.slide-container { width: 300px; }
}
CSS
๋ณต์ฌ
8.
slick ์ฌ๋ผ์ด๋ ์์ํ๊ธฐ!
a.
script.js
// ๋ฌธ์ ์ค๋น ์ด๋ฒคํธ
$(function() {
// ์ฌ๋ฆญ ์ฌ๋ผ์ด๋ ์์!
$('.slide-container').slick()
})
JavaScript
๋ณต์ฌ
9.
๋ค์ํ ์ต์
์ ์ฉํ๊ธฐ
a.
script.js
$(function() {
// ์ฌ๋ฆญ ์ฌ๋ผ์ด๋ ์์!
$('.slide-container').slick({
dots: true,
arrows: true,
autoplay: true, // ์๋์ฌ์ ์ฌ๋ถ
autoplaySpeed: 3000, // ์๋์ฌ์ ์ฌ๋ผ์ด๋ ์๊ฐ
infinite: true, // ๋ฌดํ ๋ฐ๋ณต
speed:500, // ์ฌ๋ผ์ด๋๊ฐ ์ ํ๋๋ ์๊ฐ
// centerMode: true, // ์ผํฐ ๋ชจ๋
// centerPadding: '60px', // ์ผํฐ ๋ชจ๋ ์, ๋ด๋ถ์ฌ๋ฐฑ
slidesToShow: 1, // ๋ณด์ฌ์ง ์ฌ๋ผ์ด๋ ๊ฐ์
slidesToScroll: 1, // ์คํฌ๋กค๋ ์ฌ๋ผ์ด๋ ๊ฐ์
pauseOnDotsHover: true, // ํ์ด์ง๋ค์ด์
ํธ๋ฒ ์ ์๋์ฌ์ ๋ฉ์ถค
pauseOnFocus: true, // ํฌ์ปค์ค ์, ์๋์ฌ์ ๋ฉ์ถค
pauseOnHover: true, // ํธ๋ฒ ์, ์๋์ฌ์ ๋ฉ์ถค
/* ํจ๊ณผ */
// fade: true,
// cssEase: 'linear',
// ๋ค๋น๊ฒ์ด์
ํ์ดํ ์ปค์คํ
// prevArrow: '<button class="slide-arrow prev-arrow"></button>',
// nextArrow: '<button class="slide-arrow next-arrow"></btton>',
/* ๋ฐ์ํ */
responsive: [
{
breakpoint: 1024,
settings: {
slidesToShow: 3,
slidesToScroll: 1,
}
},
{
breakpoint: 800,
settings: {
slidesToShow: 2,
slidesToScroll: 2,
}
},
{
breakpoint: 480,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
}
},
]
})
})
JavaScript
๋ณต์ฌ
10.
์ปค์คํ
a.
ํ์ดํ ์ปค์คํ
/* slick - ๋ค๋น๊ฒ์ด์
ํ์ดํ */
.prev-arrow {
position: absolute;
left: 2%;
top: 50%;
width: 40px;
height: 40px;
transform: translateY(-50%);
z-index: 100;
background: url(../img/prev.png) no-repeat center center / 40px 40px;
outline: none;
border: none;
filter: brightness(40%);
cursor: pointer;
}
.next-arrow {
position: absolute;
right: 2%;
top: 50%;
width: 40px;
height: 40px;
transform: translateY(-50%);
z-index: 100;
background: url(../img/next.png) no-repeat center center / 40px 40px;
outline: none;
border: none;
filter: brightness(40%);
cursor: pointer;
}
.prev-arrow:hover,
.next-arrow:hover {
filter: brightness(100%);
}
CSS
๋ณต์ฌ
b.
๋ท์ธ ์ปค์คํ
/* ๋ค๋น๊ฒ์ด์
๋ท์ธ ์ปค์คํ
*/
.slick-dots {
position: absolute;
bottom: -20px;
}
.slick-dots li { margin-right: 20px; }
.slick-dots li button {}
/* ๋ท์ธ */
.slick-dots li button::before {
font-size: 0;
width: 10px;
height: 10px;
background-color: sandybrown;
}
/* ํ์ฌ ๋ท์ธ */
.slick-dots li.slick-active button::before { background-color: orange; }
.nav-btn {
display: block;
padding: 5px;
margin-right: 10px;
width: 30px;
height: 30px;
line-height: 20px;
background-color: rgb(240, 196, 158);
border-radius: 50%;
color: white;
box-sizing: border-box;
}
.slick-dots li.slick-active .nav-btn {
background-color: orange;
}
CSS
๋ณต์ฌ