目录
预期效果
![](https://blog.coolight.cool/wp-content/uploads/2022/05/image-40.png)
由于audio标签自带的控制面板样式可能不合我们的心意,很多时候会想把自定义音乐播放器的样式,其中进度条也是不可少的。
- 最终将会实现如图的效果,并加上拖动进度条功能,显示已加载的比例条(图中黄色条)
实现
- 首当其冲的当然是一个<span>作为外框
- 然后搞一个<div>布局包住播放进度条和加载进度条
- 最后加入两个<span>作为进度条:
<span id="cmusic_control_span_progressBar">
<div class="cmusic_displayFlex_class cmusic_control_progress_div">
<span id="cmusic_control_span_loadProgress" style="width:80%"></span>
<span id="cmusic_control_span_progress" style="width:50%"></span>
</div>
</span>
- 给他俩搞个CSS样式
- 从预览图里我们可以发现,两个进度条是重叠的,所以显然他们的定位position要设置为绝对定位absolute。
- 然后给外框添加内阴影,显得是凹进去的一个凹槽
- 再把里面的进度条调小一些、再居中,并给与渐变色,会显得比较有青春气息
- 由于代码是从项目里拉出来的,类名啥的会长一些:
/*外框*/
#cmusic_control_span_progressBar{
border-radius: 50px;
height: 20px;
width: 100%;
display: inline-flex;
align-items: center;
position: relative;
background: transparent;
box-shadow: inset 2px 2px 4px #bcc5d6,
inset -2px -2px 5px #feffff;
border: 2px solid #d0f4ff;
justify-content: center;
transition: all 0.8s ease;
}
/*布局类*/
.cmusic_displayFlex_class {
width: 100%;
display: flex;
margin-left: auto;
margin-right: auto;
}
.cmusic_control_progress_div {
position:absolute;
width:94% !important;
height:100%;
align-items: center;
}
/*进度条*/
#cmusic_control_span_progress,
#cmusic_control_span_loadProgress{
background: linear-gradient(90deg, #c4f4fe, #66ccff);
border-radius: 50px;
position: absolute;
height: 60%;
pointer-events: none;
transition: width 0.5s ease;
box-shadow: 2px 2px 10px #ccd3ff,
-2px -2px 10px #ccd3ff;
}
/*加载进度条*/
#cmusic_control_span_loadProgress {
background: linear-gradient(90deg, #abecd6, #fff9d2);
}
- 目前效果:
- 这样基本的样子就有了,其实相当简单,就是css要搞多一点
目录
本文我们聊了如何搞出进度条的外观,接下来我们将聊聊如何让进度条跟随<audio>的已播放时长改变播放进度
- 外观
- 跟随已播放时长改变播放进度
It’s difficult to find well-informed people about this topic, however, you sound like you know what you’re talking about! Thanks
I could not refrain from commenting. Exceptionally well written!
I really like it whenever people get together and share thoughts. Great blog, continue the good work.
Pretty! This was an incredibly wonderful post. Many thanks for providing this information.
I blog quite often and I seriously thank you for your information. The article has really peaked my interest. I’m going to book mark your blog and keep checking for new information about once a week. I opted in for your Feed too.
Howdy! This blog post could not be written any better! Going through this article reminds me of my previous roommate! He constantly kept talking about this. I’ll forward this post to him. Fairly certain he will have a good read. Thanks for sharing!
Saved as a favorite, I like your web site.
You are so interesting! I don’t think I’ve truly read through anything like that before. So great to find another person with some unique thoughts on this subject matter. Seriously.. many thanks for starting this up. This website is one thing that’s needed on the internet, someone with some originality.
Good article! We are linking to this great post on our site. Keep up the great writing.
An impressive share! I’ve just forwarded this onto a colleague who was conducting a little homework on this. And he in fact bought me lunch because I discovered it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanx for spending the time to talk about this issue here on your internet site.
Excellent article. I certainly appreciate this website. Thanks!
This website was… how do I say it? Relevant!! Finally I’ve found something which helped me. Thank you.
This is a topic that’s close to my heart… Cheers! Exactly where are your contact details though?
This site definitely has all the information and facts I wanted concerning this subject and didn’t know who to ask.
Right here is the right site for anyone who hopes to find out about this topic. You realize so much its almost tough to argue with you (not that I personally will need to…HaHa). You certainly put a fresh spin on a subject that’s been written about for decades. Wonderful stuff, just great.
I was able to find good advice from your articles.
It’s hard to come by knowledgeable people about this topic, however, you sound like you know what you’re talking about! Thanks
The next time I read a blog, I hope that it won’t disappoint me as much as this one. After all, I know it was my choice to read, nonetheless I truly thought you’d have something useful to say. All I hear is a bunch of crying about something that you can fix if you weren’t too busy searching for attention.
paxlovid pill: paxlovid buy – paxlovid for sale