用html喜欢的音乐盒子制作有创意
时间: 2024-03-27 08:36:24 浏览: 19
当然可以,以下是一个简单的创意音乐盒子的HTML代码示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>创意音乐盒子</title>
<meta charset="UTF-8">
<style>
/* 样式表 */
body {
background-color: #F5F5F5;
font-family: Arial, sans-serif;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.music-box {
background-color: #FFFFFF;
border-radius: 10px;
padding: 20px;
width: 500px;
box-shadow: 0px 0px 10px #999999;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
}
h1 {
color: #333333;
margin-top: 0px;
}
p {
margin-top: 10px;
}
button {
display: block;
margin: 20px auto;
padding: 10px 20px;
border-radius: 5px;
border: none;
background-color: #333333;
color: #FFFFFF;
cursor: pointer;
font-size: 16px;
}
audio {
display: none;
}
</style>
</head>
<body>
<div class="music-box">
<h1>创意音乐盒子</h1>
<p>点击下面的按钮,播放你最喜欢的歌曲</p>
<button onclick="playSong()">播放</button>
<audio id="myAudio" autoplay>
<source src="song.mp3" type="audio/mpeg">
</audio>
</div>
<script>
function playSong() {
var x = document.getElementById("myAudio");
x.play();
}
</script>
</body>
</html>
```
这个音乐盒子会自动播放一个预设的歌曲,并且提供一个按钮供用户点击播放或暂停音乐。你可以将预设的歌曲替换成用户最喜欢的歌曲,也可以增加音量控制、歌词显示等功能,创造出更加有创意的音乐盒子。
相关推荐
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)