html圆形音乐播放器
时间: 2023-09-04 09:15:39 浏览: 86
html 音乐播放器
下面是一个基本的 HTML 圆形音乐播放器的示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>圆形音乐播放器</title>
<style type="text/css">
.circle {
width: 200px;
height: 200px;
border-radius: 50%;
background-color: #333;
position: relative;
overflow: hidden;
}
.circle img {
width: 100%;
height: 100%;
object-fit: cover;
}
.circle:before {
content: "";
display: block;
padding-top: 100%;
}
.circle .play-button {
width: 60px;
height: 60px;
border-radius: 50%;
background-color: #fff;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
cursor: pointer;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
}
.circle .play-button:before {
content: "";
display: block;
width: 0;
height: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-left: 25px solid #333;
position: absolute;
left: 22px;
top: 15px;
}
.circle.playing .play-button:before {
border-left: none;
border-right: 25px solid #333;
left: 28px;
}
.circle .progress-bar {
width: 100%;
height: 5px;
background-color: #fff;
position: absolute;
bottom: 0;
left: 0;
z-index: 1;
visibility: hidden;
}
.circle.playing .progress-bar {
visibility: visible;
}
.circle .progress-bar .progress {
width: 0;
height: 100%;
background-color: #FFD700;
}
.circle .progress-bar .progress.animate {
animation-name: progress;
animation-duration: 3s;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
@keyframes progress {
from { width: 0; }
to { width: 100%; }
}
</style>
</head>
<body>
<div class="circle">
<img src="music.jpg">
<div class="play-button"></div>
<div class="progress-bar">
<div class="progress"></div>
</div>
</div>
<audio id="myAudio" src="music.mp3"></audio>
<script type="text/javascript">
var audio = document.getElementById("myAudio");
var playButton = document.getElementsByClassName("play-button")[0];
var progressBar = document.getElementsByClassName("progress")[0];
var circle = document.getElementsByClassName("circle")[0];
var isPlaying = false;
playButton.addEventListener("click", function() {
if (isPlaying) {
audio.pause();
playButton.classList.remove("playing");
progressBar.classList.remove("animate");
isPlaying = false;
} else {
audio.play();
playButton.classList.add("playing");
progressBar.classList.add("animate");
isPlaying = true;
}
});
audio.addEventListener("timeupdate", function() {
var progress = audio.currentTime / audio.duration;
progressBar.style.width = progress * 100 + "%";
});
audio.addEventListener("ended", function() {
playButton.classList.remove("playing");
progressBar.classList.remove("animate");
isPlaying = false;
});
</script>
</body>
</html>
```
这个播放器有一个圆形的外观,包括一个播放/暂停按钮和一个进度条。你可以将你的音乐文件的路径替换为 `src` 属性的值。
阅读全文