swiper ๋ผ์ด๋ธ๋ฌ๋ฆฌ
1. swiper ํ๋ฌ๊ทธ์ธ ๊ฐ์ ธ์ค๊ธฐ
index.html
<!-- swiper ํ๋ฌ๊ทธ์ธ -->
<link rel="stylesheet" href="https://unpkg.com/swiper@7/swiper-bundle.min.css"/>
<link rel="stylesheet" href="css/style.css">
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<!-- swiper ํ๋ฌ๊ทธ์ธ -->
<script src="https://unpkg.com/swiper@7/swiper-bundle.min.js"></script>
<script src="js/script.js"></script>
HTML
๋ณต์ฌ
2. swiper HTML ๋ ์ด์์ ์ฝ๋
index.html
<!-- Slider main container -->
<div class="swiper">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
...
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<!-- If we need scrollbar -->
<div class="swiper-scrollbar"></div>
</div>
HTML
๋ณต์ฌ
3. ๊ธฐ๋ณธ ์คํ์ผ ์ง์
style.css
.swiper {
width: 600px;
height: 300px;
}
CSS
๋ณต์ฌ
4. swiper ์์ํ๊ธฐ
script.js
$(function () {
// ์ค์์ดํผ ์์!
const swiper = new Swiper('.swiper', {
// Optional parameters
direction: 'vertical',
loop: true,
// If we need pagination
pagination: {
el: '.swiper-pagination',
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// And if we need scrollbar
scrollbar: {
el: '.swiper-scrollbar',
},
});
})
JavaScript
๋ณต์ฌ
5. ์ด๋ฏธ์ง ์ ์ฉํ๊ธฐ
<!-- Slider main container -->
<div class="swiper">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<!-- (.swiper-slide>img[src="../img/slide$$.jpg"])*10 -->
<div class="swiper-slide"><img src="img/slide01.jpg" alt=""></div>
<div class="swiper-slide"><img src="img/slide02.jpg" alt=""></div>
<div class="swiper-slide"><img src="img/slide03.jpg" alt=""></div>
<div class="swiper-slide"><img src="img/slide04.jpg" alt=""></div>
<div class="swiper-slide"><img src="img/slide05.jpg" alt=""></div>
<div class="swiper-slide"><img src="img/slide06.jpg" alt=""></div>
<div class="swiper-slide"><img src="img/slide07.jpg" alt=""></div>
<div class="swiper-slide"><img src="img/slide08.jpg" alt=""></div>
<div class="swiper-slide"><img src="img/slide09.jpg" alt=""></div>
<div class="swiper-slide"><img src="img/slide10.jpg" alt=""></div>
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<!-- If we need scrollbar -->
<div class="swiper-scrollbar"></div>
</div>
HTML
๋ณต์ฌ
6. ๋ค์ํ ์ต์
$(function() {
const swiper = new Swiper('.swiper', {
// Optional parameters
direction: 'horizontal', /* ์ฌ๋ผ์ด๋ ๋ฐฉํฅ : 'vertical' , 'horizontal' */
loop: true, // ๋ฐ๋ณต์ฌ๋ถ
autoplay: { // ์๋์ฌ์
delay: 3000, // ์ฌ๋ผ์ด๋ ๋น ์ง์ฐ์๊ฐ (ms)
pauseOnMouseEnter: false, // ๋ง์ฐ์ค ์ฌ๋ฆฌ๋ฉด, ์๋์ฌ์ ๋ฉ์ถค
disableOnInteraction: false, // ์ธํฐ๋ ์
(ํ์ดํ,๋๋๊ทธ,...) ์ค ์๋์ฌ์ ๋นํ์ฑํ
},
speed: 2000, // ์ฌ๋ผ์ด๋๊ฐ ๋์ด๊ฐ๋ ์๊ฐ (ms)
slidesPerView: 1, // ๋ณด์ฌ์ง๋ ์ฌ๋ผ์ด๋ ๊ฐ์
spaceBetween: 0, // ์ฌ๋ผ์ด๋ ๊ฐ ์ฌ๋ฐฑ
grabCursor: true, // ๋ง์ฐ์ค์ปค์๋ฅผ ์ก๋ ์๊ฐ๋ฝ ๋ชจ์
centeredSlides: true, // ์ผํฐ๋ชจ๋
/* ๋ค์ํ ํจ๊ณผ */
// fade
/*
effect: "fade",
fadeEffect: {
crossFade: true
},
*/
// coverflow
/*
effect: "coverflow",
coverflowEffect: {
rotate: 20,
slideShadows: true,
scale: 1,
},
*/
// cube
/*
effect: 'cube',
cubeEffect: {
shadow: false,
slideShadow: false,
},
*/
// cards
effect: 'cards',
cardsEffect: {
rotate: false,
},
// If we need pagination
pagination: {
el: '.swiper-pagination',
type: 'bullets', // 'bullets' : โ โ โ
// 'fraction' : (ํ์ฌ๋ฒํธ/์ ์ฒด๋ฒํธ)
// 'progressbar' : ์งํ๋ฅ (๊ฒ์ด์ง)
clickable: true,
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// And if we need scrollbar
scrollbar: {
el: '.swiper-scrollbar', // ์คํฌ๋กค๋ฐ๊ฐ ์ ์ฉ๋ ์์
hide: true, // ์คํฌ๋กค๋ฐ ์จ๊น(์ง์ ์์ง์ผ ๋๋ ๋ณด์ด๊ณ , ๊ทธ์ธ์ ์จ๊น)
draggable: true, // ์คํฌ๋กค๋ฐ ๋๋๊ทธ ๊ฐ๋ฅ ์ฌ๋ถ
snapOnRelease: true, // ์คํฌ๋กค๋ฐ ๋์ ๋, ์ฌ๋ผ์ด๋ ์์น ๋ง์ถค
},
});
})
JavaScript
๋ณต์ฌ