Skip to content

Commit

Permalink
ref btns
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry committed Aug 13, 2024
1 parent 59a8e7f commit b3b3dc8
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 22 deletions.
3 changes: 3 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { API } from "./api.js";
import { initPlayBtn } from "./modules/update-cassette-btns.js";
import { updateContent } from "./modules/update-audio-dom.js";
import {
addHandlerClickPlayBtn,
removeHandlerClickPlayBtn,
} from "./modules/update-dom.js";

export const appCreate = () => {
initPlayBtn();

const btnPlay = document.querySelector(".cassette__button-play");
let audio = null;
const updateAudioData = (audioData) => {
Expand Down
Binary file added src/assets/images/btn-play-bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 21 additions & 5 deletions src/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
position: relative;
}

.cassette__disc {
position: absolute;
top: 71px;
}

@keyframes discRotate {
to {
transform: rotate(1turn);
Expand All @@ -19,11 +24,6 @@
animation: 6s infinite linear discRotate;
}

.cassette__disc {
position: absolute;
top: 71px;
}

.cassette__disc--left {
left: 113px;
}
Expand Down Expand Up @@ -58,16 +58,32 @@
width: 72px;
height: 56px;
display: block;
position: relative;
display: flex;
justify-content: center;
align-items: center;
background-color: #334155;
border-radius: 4px;
}

.cassette__button-play-inner::before {
content: "";
position: absolute;
width: 72px;
height: 56px;
top: 0;
left: 0;
background-image: url(../assets/images/btn-play-bg.png);
}

.cassette__button-play-icon {
display: block;
margin-left: 1px;
z-index: 1;
}

.cassette__button-pause-icon {
z-index: 1;
}

/* content */
Expand Down
15 changes: 1 addition & 14 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,7 @@
/>

<button class="cassette__button-play">
<span class="cassette__button-play-inner">
<svg
class="cassette__button-play-icon"
xmlns="http://www.w3.org/2000/svg"
width="30"
height="30"
fill="none"
>
<path
fill="#E2E8F0"
d="M9.125 6.25v17.5L22.875 15 9.125 6.25Z"
/>
</svg>
</span>
<span class="cassette__button-play-inner"></span>
</button>
</div>
</div>
Expand Down
41 changes: 41 additions & 0 deletions src/modules/update-cassette-btns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const btnPlayIcon = `
<svg
class="cassette__button-play-icon"
xmlns="http://www.w3.org/2000/svg"
width="30"
height="30"
fill="none"
>
<path fill="#E2E8F0" d="M8 6h3v18H8zm11 0h3v18h-3z" />
</svg>
`;

const btnPauseIcon = `
<svg
class="cassette__button-pause-icon"
xmlns="http://www.w3.org/2000/svg"
width="30"
height="30"
fill="none"
>
<path fill="#E2E8F0" d="M9.125 6.25v17.5L22.875 15 9.125 6.25Z" />
</svg>
`;

const btnPlayInner = document.querySelector(".cassette__button-play-inner");

export const initPlayBtn = () => {
btnPlayInner.insertAdjacentHTML("beforeend", btnPauseIcon);
};

export const changeOnPlayBtn = () => {
const existIcon = document.querySelector(".cassette__button-pause-icon");
btnPlayInner.removeChild(existIcon);
btnPlayInner.insertAdjacentHTML("beforeend", btnPlayIcon);
};

export const changeOnPauseBtn = () => {
const existIcon = document.querySelector(".cassette__button-play-icon");
btnPlayInner.removeChild(existIcon);
btnPlayInner.insertAdjacentHTML("beforeend", btnPauseIcon);
};
9 changes: 6 additions & 3 deletions src/modules/update-dom.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { API } from "../api.js";
import { changeOnPlayBtn, changeOnPauseBtn } from "./update-cassette-btns.js";
import {
addCassetteAnimation,
removeCassetteAnimation,
} from "./animate-cassette.js";
import { API } from "../api.js";

const btnPlay = document.querySelector(".cassette__button-play");

Expand All @@ -12,8 +13,9 @@ const createOnClickPlayBtn = (audio) => {
btnPlay.classList.remove("active");
if (!audio.paused) {
audio.pause();
changeOnPauseBtn();
removeCassetteAnimation();
}
removeCassetteAnimation();
} else {
btnPlay.classList.add("active");
if (audio.paused) {
Expand All @@ -23,8 +25,9 @@ const createOnClickPlayBtn = (audio) => {
};
API.requestCurrentTime(getCurrentTime);
audio.play();
changeOnPlayBtn();
addCassetteAnimation();
}
addCassetteAnimation();
}
};
};
Expand Down

0 comments on commit b3b3dc8

Please sign in to comment.