一、功能简介
可以实现简单的暂停,播放,拖动进度等简单的操作
二、功能实现的过程
1、整体分析
我们先在index.html里面写基本的样式,然后将具体的功能实现封装在一个类里,遇到工具类的功能的话,比如时长的转换,就单独分装成一个工具类来处理。
2、样式与布局
*{
margin: 0;
padding: 0;
}
.wrap{
width:400px;
background-color: #aaa;
padding: 20px;
}
.player{
display: flex;
flex-direction: row;
align-items: center;
}
.title{
text-align: center;
color: #FFF;
}
.btn{
width: 7px;
height: 7px;
border-radius: 10px;
background: #FFFFFF;
position: absolute;
top:-3px;
}
.line{
position: relative;
height: 2px;
background-color: #ccc;
margin: 0 10px;
flex-grow: 1;
}
3、具体功能分析(使用audio的API)
(1)播放
(2)暂停
(3)拖动
class Player {
constructor(musicNameEle, startTimeEle, alltimeEle, btnEle, audioEle) {
this