이미지 슬라이드 - 좌로 움직이기
<main>
<section id="sliderType01">
<div class="slider__wrap">
<div class="slider__img">
<div class="slider"><img src="img/image06.jpg" alt="이미지1"></div>
<div class="slider"><img src="img/image07.jpg" alt="이미지2"></div>
<div class="slider"><img src="img/image08.jpg" alt="이미지3"></div>
<div class="slider"><img src="img/image09.jpg" alt="이미지4"></div>
<div class="slider"><img src="img/image10.jpg" alt="이미지5"></div>
</div>
</div>
</section>
</main>
<!--//main-->
<!--info-->
<div class="info">
<div class="title">
<h1><a href="sliderEffect.html">Javascript SliderEffect01</a>
<p>이미지 슬라이드 - 페이드 효과</p>
</div>
<div class="number">
<ul>
<li class="active"><a href="sliderEffect01.html">1</a>
<li><a href="sliderEffect02.html">2</a></li>
<li><a href="sliderEffect03.html">3</a></li>
<li><a href="sliderEffect04.html">4</a></li>
<li><a href="sliderEffect05.html">5</a></li>
<li><a href="sliderEffect06.html">6</a></li>
<li><a href="sliderEffect07.html">7</a></li>
<li><a href="sliderEffect08.html">8</a></li>
</ul>
</div>
<div class="source">
<button class="source-btn">소스보기
<div id="modal">
<div class="modal-wrap">
<div class="modal-cont">
<div class="code-view">
<div class="view-header" aria-hidden="true">
<span></span>
<span></span>
<span></span>
</div>
<div class="view-title">
<ul>
<li class="active"><a href="#">HTML</a>
<li><a href="#">CSS</a>
<li><a href="#">Javascript</a>
<li><a href="#">jQuery</a>
</ul>
</div>
<div class="view-cont"> *4
</div>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'NexonLv1Gothic';
}
a {
text-decoration: none;
color: #fff;
transition: all 0.2s;
}
li {
list-style: none;
}
img {
width: 100%;
vertical-align: top; /*이미지 여백 제거*/
}
body {
width: 100%;
height: 100vh;
background: url(../../effect/img/image01.jpg);
background-size: cover;
background-position: center center;
overflow: hidden;
color: #fff;
}
body.img01 {
background-image: url(../../effect/img/image01.jpg);
}
body.img02 {
background-image: url(../../effect/img/image02.jpg);
}
body.img03 {
background-image: url(../../effect/img/image03.jpg);
}
body.img04 {
background-image: url(../../effect/img/image04.jpg);
}
body.img05 {
background-image: url(../../effect/img/image05.jpg);
}
body.img06 {
background-image: url(../../effect/img/image06.jpg);
}
body.img07 {
background-image: url(../../effect/img/image07.jpg);
}
body.img08 {
background-image: url(../../effect/img/image08.jpg);
}
body::before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100vh;
background: rgba(22,25,28,0.7);
z-index: -1;
}
/*info*/
.title {
position: absolute;
left: 20px;
top: 20px;
}
.title h1 {
font-size: 34px;
border-bottom: 1px dashed #fff;
margin-bottom: 8px;
padding-bottom: 5px;
letter-spacing: 2px;
}
.title p {
font-size: 18px;
}
.number {
position: absolute;
right: 20px;
top: 20px;
}
.number li {
display: inline;
}
.number li a {
display: inline-block;
width: 30px;
height: 30px;
border: 1px solid #fff;
border-radius: 10px;
text-align: center;
line-height: 30px;
font-size: 12px;
}
.number li a:hover {
background: #fff;
color: #000;
}
.number li.active a {
background: #fff;
color: #000;
}
.source {
position: absolute;
right: 20px;
bottom: 20px;
}
.source button {
border: 1px solid #fff;
background: transparent;
font-family: 'NexonLv1Gothic';
color: #fff;
font-size: 16px;
padding: 10px 30px;
border-radius: 50px;
transition: all 0.2s;
cursor: pointer;
}
.source button:hover {
background: #fff;
color: #000;
}
/*modal*/
#modal {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100vh;
background: rgba(0,0,0,0.4);
z-index: 1000;
transform: scale(0);
}
#modal.show {
animation: foldOut 1s ease forwards;
}
#modal.show.hide {
animation: foldIn 1s 0.3s ease backwards;
}
.modal-wrap {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
height: 100vh;
transform: scale(0);
}
#modal.show .modal-wrap {
animation: zoomOut 0.5s 1s ease forwards;
}
#modal.show.hide .modal-wrap {
animation: zoomIn 0.5s ease forwards;
}
@keyframes foldOut {
0% {transform: scaleX(0) scaleY(0.005)}
50% {transform: scaleX(1) scaleY(0.005)}
100% {transform: scaleX(1) scaleY(1)}
}
@keyframes foldIn {
0% {transform: scaleX(1) scaleY(1)}
50% {transform: scaleX(1) scaleY(0.005)}
100% {transform: scaleX(0) scaleY(0.005)}
}
@keyframes zoomOut {
0% {transform: scale(0)}
100% {transform: scale(1)}
}
@keyframes zoomIn {
0% {transform: scale(1)}
100% {transform: scale(0)}
}
.modal-close {
margin-top: 10px;
}
.modal-cont {
opacity: 1;
position: relative;
}
.code-view {
width: 60vw;
height: 60vh;
background: #fff;
border: 1px solid #f2f2f2;
border-radius: 10px;
overflow: scroll;
overflow-x: hidden;
}
.code-view::-webkit-scrollbar {
display: none; /*나중에 필요하면 스크롤바 디자인 찾아보기*/
}
.view-header {
padding: 7px 0 7px 10px;
border-bottom: 1px solid #e2e8f0;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 32px;
background: #fff;
border-radius: 5px 5px 0 0;
}
.view-header > span {
width: 10px;
height: 10px;
display: inline-block;
border-radius: 10px;
}
.view-header > span:nth-child(1) {
background-color: #f56565;
}
.view-header > span:nth-child(2) {
background-color: #f6e05e;
}
.view-header > span:nth-child(3) {
background-color: #48bb78;
}
.view-title {
border-bottom: 1px solid #e2e8f0;
padding: 9px 10px 7px 10px;
height: 38px;
position: absolute;
left: 0;
top: 32px;
width: 100%;
background: #fff;
}
.view-title li {
display: inline;
}
.view-title li a {
color: rgb(151, 151, 151);
font-size: 16px;
text-transform: uppercase;
padding: 12px 20px 8px 20px;
margin: 2px 0px 0px 0px;
}
.view-title li.active a {
color: #000;
border-bottom: 3px solid #61aeee;
}
.view-cont {
height: 100%;
background: #282c34;
padding-top: 40px;
}
.view-cont > div {
display: none;
}
.view-cont > div:first-child {
display: block;
}
.view-cont pre code.hljs {
line-height: 1.6;
}
/*slider*/
.slider__wrap {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.slider__img { /*화면보이는 구간*/
width: 800px;
height: 480px;
overflow: hidden;
}
.slider__inner { /*이미지 움직이는 영역*/
display: flex;
flex-wrap: wrap;
width: 4000px;
position: relative; /*left를 사용하기 위해서 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';
}
//slider01
const sliderWrap = document.querySelector(".slider__wrap")
const sliderImg = document.querySelector(".slider__img") //이미지 보이는 영역
const sliderInner = document.querySelector(".slider__inner") //이미지 움직이는 영역 (틀)
const slider = document.querySelectorAll(".slider") // 5개의 이미지가 저장
let currentIndex = -1;
let sliderCount = slider.length;
setInterval(()=>{
(currentIndex<sliderCount-1) ? currentIndex++ : currentIndex = 0;
gsap.to(sliderInner, {
duration: 1.0,
left: -800 * currentIndex,
ease: "expo.out"
});
},2500);