이미지 슬라이드 - 위로 움직이기
<main>
<div class="slider-wrap">
<div class="slider-img slider-img1">
<div class="slider-inner slider-inner1">
<div class="slider slider1" data-name="이미지1">
<img src="../assets/img/bg36.jpg" alt="이미지1">
</div>
<div class="slider slider1" data-name="이미지2">
<img src="../assets/img/bg37.jpg" alt="이미지2">
</div>
<div class="slider slider1" data-name="이미지3">
<img src="../assets/img/bg38.jpg" alt="이미지3">
</div>
<div class="slider slider1" data-name="이미지4">
<img src="../assets/img/bg39.jpg" alt="이미지4">
</div>
<div class="slider slider1" data-name="이미지5">
<img src="../assets/img/bg31.jpg" alt="이미지5">
</div>
</div>
</div>
<div class="slider-img slider-img2">
<div class="slider-inner slider-inner2">
<div class="slider slider2" data-name="이미지1">
<img src="../assets/img/bg36.jpg" alt="이미지1">
</div>
<div class="slider slider2" data-name="이미지2">
<img src="../assets/img/bg37.jpg" alt="이미지2">
</div>
<div class="slider slider2" data-name="이미지3">
<img src="../assets/img/bg38.jpg" alt="이미지3">
</div>
<div class="slider slider2" data-name="이미지4">
<img src="../assets/img/bg39.jpg" alt="이미지4">
</div>
<div class="slider slider2" data-name="이미지5">
<img src="../assets/img/bg31.jpg" alt="이미지5">
</div>
</div>
</div>
</div>
</main>
/* slider */
.slider-wrap {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.slider-img {
width: 600px;
height: 360px;
overflow: hidden;
margin: 10px;
}
.slider-img img {
width: 100%;
}
.slider-inner {
position: relative;
width: 600px;
height: 1800px;
overflow: hidden;
}
.slider-inner .slider {
float: left;
width: 600px;
height: 360px;
position: relative;
}
.slider-inner .slider::before {
position: absolute;
left: 5px;
top: 5px;
background: rgba(0,0,0,.4);
color: #fff;
padding: 5px 10px 3px;
font-family: 'NEXONLv1Gothic';
}
.slider-inner .slider:nth-child(1) {
z-index: 5;
}
.slider-inner .slider:nth-child(2) {
z-index: 4;
}
.slider-inner .slider:nth-child(3) {
z-index: 3;
}
.slider-inner .slider:nth-child(4) {
z-index: 2;
}
.slider-inner .slider:nth-child(5) {
z-index: 1;
}
.slider-inner .slider::before {
content: attr(data-name);
}
// slider1
const sliderImg1 = document.querySelector(".slider-img1");
const sliderInner1 = document.querySelector(".slider-inner1");
const slider1 = document.querySelector(".slider1");
let currentIndex1 = 0;
let sliderHeight1 = slider1.offsetHeight;
sliderInner1.style.transition = "all 0.3s";
sliderInner1.style.top = "0px";
setInterval(() =>{
currentIndex1 < 4 ? currentIndex1++ : currentIndex1 = 0;
let sliderPosition = (currentIndex1 * -sliderHeight1) + "px";
sliderInner1.style.transition = "all 0.3s";
sliderInner1.style.top = sliderPosition;
}, 3000);
// slider2
const sliderImg2 = document.querySelector(".slider-img2");
const sliderInner2 = document.querySelector(".slider-inner2");
const slider2 = document.querySelector(".slider2");
let currentIndex2 = 0;
let sliderHeight2 = slider2.offsetHeight;
let sliderCount = document.querySelectorAll(".slider2").length;
let sliderClone = sliderInner2.firstElementChild.cloneNode(true);
sliderInner2.appendChild(sliderClone);
setInterval(() =>{
currentIndex2++
sliderInner2.style.transition = "all 0.3s";
sliderInner2.style.transform = "translateY(" + (-sliderHeight2 * currentIndex2) + "px)";
if(currentIndex2 == sliderCount){
setTimeout(() => {
sliderInner2.style.transition = "0s";
sliderInner2.style.transform = "translateY(0)";
}, 300);
currentIndex2 = 0;
};
}, 3000);
// 소스보기 실행함수
modal();