// 2. This code loads the IFrame Player API code asynchronously. --></script>
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
function onYouTubeIframeAPIReady() {
// <div id="player"></div>
new YT.Player('player', {
videoId: 'An6LvWQuj_8', // 최초 재생할 유투브 영상 ID
playerVars: {
autoplay: true, //자동 재생 유무
loop: true, //반복 재생 유무
playlist: 'An6LvWQuj_8' // 반복 재생할 유튜브 영상 ID 목록
},
events: {
onReady: function (event) {
event.target.mute() // 음소거
}
}
});
}
버튼(스타벅스 프로모션)을 클릭하면 아래 슬라이드 부분이 숨겨지고 나타나는 Toggle 기능
1. Swiper적용하기
1-1. Swiper API 사이트에서 스크립트 가져오기
1-2. JS에 들여오기
ㄴ Optional Parameters (옵션 내 세부옵션은 객체화시켜 삽입 / 옵션은 콤마로 구분 / 마지막 콤마는 생략)
new Swiper('.promotion .swiper-container', {
// direction: 'horizontal', // 수평 슬라이드
autoplay: { // 자동 재생 여부
delay: 5000 // 5초마다 슬라이드 바뀜
},
loop: true, // 반복 재생 여부
slidesPerView: 3, // 한 번에 보여줄 슬라이드 개수
spaceBetween: 10, // 슬라이드 사이 여백
centeredSlides: true, // 1번 슬라이드가 가운데 보이기
pagination: { // 페이지 번호 사용 여부
el: '.promotion .swiper-pagination', // 페이지 번호 요소 선택자
clickable: true // 사용자의 페이지 번호 요소 제어 가능 여부
},
navigation: { // 슬라이드 이전/다음 버튼 사용 여부
prevEl: '.promotion .swiper-prev', // 이전 버튼 선택자
nextEl: '.promotion .swiper-next' // 다음 버튼 선택자
}
})
2. pagination 스타일 추가
📍 swiper 라이브러리에서 기본으로 스타일을 제공하기 때문에 개발도구를 열어 적용된 스타일을 확인한다.
📍 기본으로 제공하는 클래스명 : swiper-pagination-bullet / swiper-pagination-bullet-active