이미지 슬라이드 - 페이드 효과
<main>
<section id="sliderType01">
<div class="slider__wrap">
<div class="slider__img">
<div class="slider"><img src="img/image01.jpg" alt="이미지1"></div>
<div class="slider"><img src="img/image02.jpg" alt="이미지2"></div>
<div class="slider"><img src="img/image03.jpg" alt="이미지3"></div>
<div class="slider"><img src="img/image04.jpg" alt="이미지4"></div>
<div class="slider"><img src="img/image05.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::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: 65px;
}
.view-cont > div {
display: none;
}
.view-cont > div:first-child {
display: block;
}
.view-cont pre code.hljs {
line-height: 1.6;
}
//slider01
const sliderWrap = document.querySelector(".slider__wrap")
const sliderImg = document.querySelector(".slider__img")
const slider = document.querySelectorAll(".slider")
let currentIndex = 0; //현재 보이는 이미지
let sliderCount = slider.length; //이미지 갯수
setInterval(() => {
let nextIndex =(currentIndex + 1) % 5; //1 2 3 4 0 1 2 3 4 0... 5로 나눠서 나머지 값만 나오게.
slider[currentIndex].style.opacity = "0" //첫 번째 이미지를 안보이게
slider[nextIndex].style.opacity = "1" //두 번째 이미지를 보이게
currentIndex = nextIndex; //nextIndex 값을 currentIndex에 대입시켜서 계속 반복.
slider.forEach(slider => {
slider.style.transition = "all 0.3s"; //트랜지션 효과를 써서 부드럽게 움직이도록
});
}, 2000);
//jQuery를 이용한 방법. -modal
const modal = function(){
$(".source-btn").click(()=>{
$("#modal").addClass("show");
})
$(".modal-close").click(()=>{
$("#modal").removeClass("show");
})
}
modal();