Search

slick

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
๋ณต์‚ฌ
b.
FILE ๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ
<!-- slick css FILE --> <link rel="stylesheet" href="css/slick.css"> <link rel="stylesheet" href="css/slick-theme.css"> <!-- slick js FILE --> <script src="js/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
๋ณต์‚ฌ