이미지 슬라이드 - 좌로 움직이기
<main>
<section id="sliderType01">
<div class="slider__wrap">
<div class="slider__img">
<div class="slider__inner">
<div class="slider"><img src="img/img06.jpg" alt="이미지1"></div>
<div class="slider"><img src="img/img07.jpg" alt="이미지2"></div>
<div class="slider"><img src="img/img08.jpg" alt="이미지3"></div>
<div class="slider"><img src="img/img09.jpg" alt="이미지4"></div>
<div class="slider"><img src="img/img10.jpg" alt="이미지5"></div>
</div>
</div>
</div>
</section>
</main>
.slider__wrap {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.slider__img {
width: 800px;
height: 480px;
overflow: hidden;
}
.slider__inner {
display: flex;
width: 4000px;
position: relative;
}
.slider {
width: 800px;
position: relative;
}
.slider::before {
position: absolute;
left: 5px;
top: 5px;
background: rgba(0, 0, 0, 0.4);
color: #fff;
padding: 5px 10px 3px;
}
.slider:nth-child(1)::before {
content: '이미지1';
}
.slider:nth-child(2)::before {
content: '이미지2';
}
.slider:nth-child(3)::before {
content: '이미지3';
}
.slider:nth-child(4)::before {
content: '이미지4';
}
.slider:nth-child(5)::before {
content: '이미지5';
}
const sliderWrap = document.querySelector(".slider__wrap");
const sliderImg = document.querySelector(".slider__img");
const sliderInner = document.querySelector(".slider__inner");
const slider = document.querySelectorAll(".slider");
let currentIndex = -1;
let sliderCount = slider.length;
setInterval(()=>{
console.log(currentIndex);
(currentIndex < sliderCount-1) ? currentIndex++ : currentIndex = 0;
gsap.to(sliderInner, {
duration: 0.4,
ease: "back.out(1.7)",
left: -800 * currentIndex
})
}, 2000)