728x90
반응형
.play css edit
CD 돌아가는 효과넣기
.pic after 가상요소에 애니메이션을 준다.
script
기존에 만들었던 el list에 스크립트를 추가한다.
play라고 변수 지정
● target: 선택된 객체, target은 오류가 있을 수 있다.
● currentTarget: 오류를 줄이기 위해서 추가된 태그. 이벤트를 갖고있는 아이가 선택되면 이벤트가 실행
간혹 선택되는 아이는 다른아인데 실행되는 아이가 다를 수 있다. 그러한 오류를 방지하기 위해 currentTarget을 사용
●tagName: 태그 네임을 가지고 와라
● closest : 상위 부모를 찾음
●classList: =addclass
플레이 버튼을 누르면 시디가 돌아간다.
그림자도 같이 돌리기
pause 누를 시에 CD 멈추기
audio (음악) 넣기
reload script추가
버튼 추가
<HTML>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>music player</title>
<link rel="stylesheet" href="./css/all.min.css">
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<figure>
<h1>
<strong>DJ CHO</strong>
<span>UI/UX DESIGN & DEVELOPMENT</span>
</h1>
<a href="#" class="menu"><i class="fa-solid fa-bars"></i></a>
<p>2023 Designed by CHO</p>
<section>
<article class="article1 on">
<div class="inner">
<div class="pic">
<div class="dot"></div>
</div>
<div class="txt">
<h2>Blizzards</h2>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit.</p>
<ul>
<li class="pause">
<i class="fa-solid fa-pause"></i>
</li>
<li class="play">
<i class="fa-solid fa-play"></i>
</li>
<li class="reload">
<i class="fa-solid fa-rotate-right"></i>
</li>
</ul>
<audio src="./img/music/Blizzards.mp3"></audio>
</div>
</div>
</article>
<article class="article2">
<div class="inner">
<div class="pic">
<div class="dot"></div>
</div>
<div class="txt">
<h2>Calm</h2>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit.</p>
<ul>
<li class="pause">
<i class="fa-solid fa-pause"></i>
</li>
<li class="play">
<i class="fa-solid fa-play"></i>
</li>
<li class="reload">
<i class="fa-solid fa-rotate-right"></i>
</li>
</ul>
<audio src="./img/music/Calm.mp3"></audio>
</div>
</div>
</article>
<article class="article3">
<div class="inner">
<div class="pic">
<div class="dot"></div>
</div>
<div class="txt">
<h2>Dusty_Road</h2>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit.</p>
<ul>
<li class="pause">
<i class="fa-solid fa-pause"></i>
</li>
<li class="play">
<i class="fa-solid fa-play"></i>
</li>
<li class="reload">
<i class="fa-solid fa-rotate-right"></i>
</li>
</ul>
<audio src="./img/music/Dusty_Road.mp3"></audio>
</div>
</div>
</article>
<article class="article4">
<div class="inner">
<div class="pic">
<div class="dot"></div>
</div>
<div class="txt">
<h2>Escape</h2>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit.</p>
<ul>
<li class="pause">
<i class="fa-solid fa-pause"></i>
</li>
<li class="play">
<i class="fa-solid fa-play"></i>
</li>
<li class="reload">
<i class="fa-solid fa-rotate-right"></i>
</li>
</ul>
<audio src="./img/music/Escape.mp3"></audio>
</div>
</div>
</article>
<article class="article5">
<div class="inner">
<div class="pic">
<div class="dot"></div>
</div>
<div class="txt">
<h2>Payday</h2>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit.</p>
<ul>
<li class="pause">
<i class="fa-solid fa-pause"></i>
</li>
<li class="play">
<i class="fa-solid fa-play"></i>
</li>
<li class="reload">
<i class="fa-solid fa-rotate-right"></i>
</li>
</ul>
<audio src="./img/music/Payday.mp3"></audio>
</div>
</div>
</article>
<article class="article6">
<div class="inner">
<div class="pic">
<div class="dot"></div>
</div>
<div class="txt">
<h2>Retreat</h2>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit.</p>
<ul>
<li class="pause">
<i class="fa-solid fa-pause"></i>
</li>
<li class="play">
<i class="fa-solid fa-play"></i>
</li>
<li class="reload">
<i class="fa-solid fa-rotate-right"></i>
</li>
</ul>
<audio src="./img/music/Retreat.mp3"></audio>
</div>
</div>
</article>
<article class="article7">
<div class="inner">
<div class="pic">
<div class="dot"></div>
</div>
<div class="txt">
<h2>Seasonal</h2>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit.</p>
<ul>
<li class="pause">
<i class="fa-solid fa-pause"></i>
</li>
<li class="play">
<i class="fa-solid fa-play"></i>
</li>
<li class="reload">
<i class="fa-solid fa-rotate-right"></i>
</li>
</ul>
<audio src="./img/music/Seasonal.mp3"></audio>
</div>
</div>
</article>
<article class="article8">
<div class="inner">
<div class="pic">
<div class="dot"></div>
</div>
<div class="txt">
<h2>Vespers</h2>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit.</p>
<ul>
<li class="pause">
<i class="fa-solid fa-pause"></i>
</li>
<li class="play">
<i class="fa-solid fa-play"></i>
</li>
<li class="reload">
<i class="fa-solid fa-rotate-right"></i>
</li>
</ul>
<audio src="./img/music/Vespers.mp3"></audio>
</div>
</div>
</article>
</section>
<div class="btnPrev">
<span>PREV MUSIC</span>
</div>
<div class="btnNext">
<span>NEXT MUSIC</span>
</div>
</figure>
<!-- article 회전배치하기 -->
<script>
// document 안에 있는 section을 선택하겠다
const frame = document.querySelector("section");
//frame 안에있는 article들을 선택하겠다.
const lists = frame.querySelectorAll("article");
const deg = 45;
const len = lists.length; //.length: 갯수를 구하는 명령어
// console.log(len)
let i=0;
for(let el of lists){
let pic = el.querySelector(".pic");
// CD 돌아가는 효과
let play = el.querySelector(".play");
// CD 멈춤 효과
let pause = el.querySelector(".pause");
let reload = el.querySelector(".reload")
el.style.transform = `rotate(${i * deg}deg) translateY(-100vh)`;
pic.style.backgroundImage = `url(../img/member${i+1}.jpg)`;
i++;
//reload 클릭 시 이벤트
reload.addEventListener("click",(e)=>{
e.currentTarget.closest("article").querySelector(".pic").classList.add("on");
e.currentTarget.closest("article").querySelector("audio").load();
e.currentTarget.closest("article").querySelector("audio").play();
});
//CD멈춤효과, pause 클릭시 이벤트
pause.addEventListener("click",(e)=>{
e.currentTarget.closest("article").querySelector(".pic").
classList.remove("on");
e.currentTarget.closest("article").querySelector("audio")
.pause();
});
// CD 돌아가는 효과, Play 클릭 시 이벤트
play.addEventListener("click",(e)=>{
e.currentTarget.closest("article").querySelector(".pic").classList.add("on");
//음악넣기
e.currentTarget.closest("article").querySelector("audio")
.play();
});
//currentTarget:이벤트 리스너를 가지고 있는 요소를 선택
//closest:가장 가까운 상위요소(article)를 선택
}
</script>
</body>
</html>
<CSS>
@charset "utf-8";
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
li,ul,ol{list-style: none;}
a{text-decoration: none;}
figure{
width: 100%;
height: 100vh;
background: linear-gradient(25deg, violet,pink);
overflow: hidden;
position: relative;
}
figure h1{
position: absolute;
top: 7vh;
left: 4vw;
color: #fff;
/* font-size: 0을 주면 strong(display:block 시)과 span사이 줄간격을 줄일 수 있다. */
font-size: 0;
}
figure h1 strong{
font-size: 36px;
display: block;
letter-spacing: 1px;
}
figure h1 span{
font-size: 12px;
letter-spacing: 1px;
}
figure > .menu{
position: absolute;
top: 7vh;
right: 4vw;
font-size: 24px;
color: #fff;
}
figure > p{
position: absolute;
bottom: 7vh;
left: 50%;
transform: translateX(-50%);
font-size: 12px;
color: #fff;
}
figure section{
width: 20vw;
height: 65vh;
/* border: 1px solid aqua; */
position: absolute;
left: 50%;
top: 140%;
margin-top: -25vh;
margin-left: -10vw;
}
figure section article{
/* section의 너비값, 높이값을 받음(20vw) */
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
figure section article .inner{
width: 100%;
height: 100%;
background-color: #f0f7ff;
padding: 5vh 2.5vw 8vh 2.5vw;
border-radius: 10px;
box-shadow: 10px 10px 20px rgba(0, 0, 0, 0.1);
opacity: 0.6;
/* 박스사이즈 축소 */
transform: scale(0.7);
}
figure section article.on .inner{
transform: scale(1);
opacity: 0.9
}
figure section article .inner .pic{
/* 너비, 높이값을 같이 vw를 주면 정사각형이 된다. */
width: 15vw;
height: 15vw;
background-color: #ccc;
margin: 0 auto;
border-radius: 50%;
/* 이미지 반복해제 */
background-repeat: no-repeat;
/* .dot 가운데 정렬 */
display: flex;
justify-content: center;
align-items: center;
/* .pic가상요소의 기준점 */
position: relative;
}
/* 가상요소 */
figure section article .inner .pic::before,
figure section article .inner .pic::after{
content: "";
display: block;
/* 너비,높이,보더값 부모 상속받아서 적용 */
width: inherit;
height: inherit;
border-radius: inherit;
background-image: inherit;
background-position: inherit;
background-repeat: inherit;
background-size: cover;
transform-origin: center center;
position: absolute;
top: 0;
left: 0;
}
/* before(먼저만들어진 요소)로 해주어야 뒤에 가상요소가 내려온다. 그림자*/
figure section article .inner .pic::before{
transform: translateY(10%);
filter: blur(18px) brightness(1.6);
}
figure section article .inner .pic .dot{
width: 3vw;
height: 3vw;
background-color: #e4f1ff;
border-radius: 50%;
box-shadow: 3px 3px 7px rgba(0, 0, 0, 0.2) inset;
z-index: 10;
}
figure section article .inner .txt{
text-align: center;
margin-top: 5vh;
}
figure section article .inner .txt h2{
font-size: 20px;
font-family: "arial";
color: #333;
margin-bottom: 2vh;
}
figure section article .inner .txt p{
font-size: 12px;
margin-bottom: 3vh;
}
figure section article .inner .txt ul{
/* li 가로로 정렬 */
display: flex;
/* space-between 꽉 채운 가로정렬 */
justify-content: space-between;
}
figure section article .inner .txt ul li{
cursor: pointer;
/* on을 갖고있는 객체만 진하게하기위함 */
opacity: 0.5;
transition: all 0.5s;
}
figure section article .inner .txt ul li:hover{
transform: scale(1.5);
opacity: 0.9;
}
figure section article .inner .txt ul li.pause{ }
figure section article .inner .txt ul li.play{
transform: scale(1.5);
}
figure section article .inner .txt ul li.play:hover{
transform: scale(2);
}
figure section article .inner .txt ul li.reload{ }
/* CD 돌아가는 효과 */
figure section article .inner .pic.on::after{
animation: ani 4s linear infinite;
}
@keyframes ani{
0%{transform: rotate(0deg);}
100%{transform: rotate(360deg);}
}
/* CD 그림자 돌아가는 효과 */
figure section article .inner .pic.on::before{
animation: ani2 4s linear infinite;
}
@keyframes ani2{
0%{transform: translateY(10%) rotate(0deg); }
100%{transform: translateY(10%) rotate(360deg);}
}
figure .btnPrev{
width: 60px;
height: 60px;
/* background-color: #ccc; */
position: absolute;
left: 50%;
top: 50%;
transform: translate(-20vw,-50%);
display: flex;
align-items: center;
text-align: left;
cursor: pointer;
}
figure .btnPrev span{
font: 12px/1 "arial";
color: #fff;
opacity: 1;
transform: translateX(30%);
transition: all 0.5s;
}
figure .btnPrev:hover span{
opacity: 0;
transform: translateX(100%);
}
/* 가상요소 */
figure .btnPrev::before{
content: "";
display: block;
width: 100%;
height: 1px;
background-color: #fff;
position: absolute;
top: 50%;
left: 0;
/* 기준점 변경 */
transform-origin: left center;
transform: rotate(-180deg);
transition: all 0.5s;
}
figure .btnPrev:hover::before{
transform: rotate(-30deg);
}
figure .btnPrev::after{
content: "";
display: block;
width: 100%;
height: 1px;
background-color: #fff;
position: absolute;
bottom: 50%;
left: 0;
transform-origin: left center;
transform: rotate(180deg);
transition: all 0.5s;
}
figure .btnPrev:hover::after{
transform: rotate(30deg);
}
figure .btnNext{
width: 60px;
height: 60px;
/* background-color: #ddd; */
position: absolute;
right: 50%;
top: 50%;
transform: translate(20vw,-50%);
display: flex;
align-items: center;
text-align: right;
cursor: pointer;
}
figure .btnNext span{
font: 12px/1 "arial";
color: #fff;
opacity: 1;
transform: translateX(-30%);
transition: all 0.5s;
}
figure .btnNext:hover span{
opacity: 0;
transform: translateX(-100%);
}
figure .btnNext::before{
content: "";
display: block;
width: 100%;
height: 1px;
background-color: #fff;
position: absolute;
top: 50%;
left: 0;
/* 기준점 변경 */
transform-origin: right center;
transform: rotate(-180deg);
transition: all 0.5s;
}
figure .btnNext:hover::before{
transform: rotate(-30deg);
}
figure .btnNext::after{
content: "";
display: block;
width: 100%;
height: 1px;
background-color: #fff;
position: absolute;
bottom: 50%;
left: 0;
transform-origin: right center;
transform: rotate(180deg);
transition: all 0.5s;
}
figure .btnNext:hover::after{
transform: rotate(30deg);
}
728x90
반응형
'☭DEVELOPER > #2 웹개발(자바기반 풀스택)' 카테고리의 다른 글
비주얼 스튜디오 코드 79_뮤직 플레이어 3 (0) | 2023.07.18 |
---|---|
[JAVASCRIPT]if 조건 (0) | 2023.07.18 |
[JAVACRIPT]document.write / Data Type (0) | 2023.07.17 |
비주얼 스튜디오 코드 77_ 뮤직 플레이어 (0) | 2023.07.14 |
비주얼 스튜디오 코드 76_파노라마_완성 (0) | 2023.07.13 |