上一期我们介绍了外观设计,这把我们聊聊让进度条跟随播放进度走
目录
预期效果
准备
- 在此之前,你需要有以下基础:
- HTML/CSS/JS
- 了解一些<audio>标签的属性和事件
- Vue(数据绑定和事件绑定)
实现
- 还是上次的那个Html/css,但我们这把加入了:
- 最外围用div包裹,用于创建vue
- 添加了<audio>
- 显示音乐标签面板 (controls)
- 默认静音 (muted)
- 绑定事件:播放时长更新事件 timeupdate
- 绑定数据:音频文件资源链接 src
- 两个vue数据绑定
- cmusic_control_loadProgress_style (加载进度条长度)
- cmusic_control_progress_style (播放进度条长度)
- 修改部分css样式
- HTML:
<div id="root_div" class="cmusic_displayFlex_class" style="height:150px;justify-content:space-between;align-items: center;">
<!-- 音频 -->
<audio id="cmusic_audio" ref="cmusic_audio" controls muted
@timeupdate="audio_lengthChange()" :src="url_audio">
</audio>
<span id="cmusic_control_span_progressBar">
<div class="cmusic_displayFlex_class cmusic_control_progress_div" style="flex-direction: row;">
<span id="cmusic_control_span_loadProgress" :style="cmusic_control_loadProgress_style"></span>
<span id="cmusic_control_span_progress" :style="cmusic_control_progress_style"></span>
</div>
</span>
<div>
- CSS:
<style>
/*外框*/
#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;
flex-direction: column;
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;
width:100%;
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);
}
</style>
- 并在script标签内写js/vue代码:
<!-- 引入vue -->
<script src="https://unpkg.com/vue@3.2.33"></script>
<script>
const { createApp } = Vue
var cmusic_json = {
//数据
data() {
return {
url_audio:"https://blog.coolight.cool/wp-content/uploads/2022/05/大喜_洛天依.m4a",
cmusic_control_loadProgress_style:"width:80%",
cmusic_control_progress_style:"width:50%"
}
},
//函数
methods:{
//监听播放时长,修改进度条长度
audio_lengthChange:function(){
let caudio = this.$refs.cmusic_audio;
//duration是音频总时长
//如果音频元数据加载完成,才能获得其总时长,后续才能进行计算
if (!isNaN(caudio.duration)){
this.cmusic_control_progress_style = "width:" + (parseInt(caudio.currentTime / caudio.duration * 100)).toString() + "%;";
}else{
this.cmusic_control_progress_style = "width:0%;";
}
}
}
};
var cmusic_app = Vue.createApp(cmusic_json);
var cmusic_vue = cmusic_app.mount("#root_div");
</script>
- 最终效果:
- 默认是静音的,可以点击播放试试
After going over a handful of the blog posts on your blog, I seriously like your technique of blogging. I bookmarked it to my bookmark webpage list and will be checking back soon. Please check out my web site too and tell me your opinion.
best online ed meds: Best ED pills non prescription – affordable ed medication
I used to be able to find good information from your blog posts.
porn cannibalism
Do not leave it too late to find out how vulnerable your business really is – call on the skills of the experts.
Hiya very nice blog!! Guy .. Excellent .. Amazing .. I will bookmark your website and take the feeds also…I am happy to find so many useful info here within the put up, we want develop extra strategies on this regard, thanks for sharing. . . . . .
http://mexicopharmacy.win/# mexican border pharmacies shipping to usa
http://indiapharmacy.shop/# india online pharmacy
boner pills online: Best ED pills non prescription – ed doctor online
buying prescription drugs in mexico: mexican online pharmacies prescription drugs – mexico pharmacies prescription drugs
The reason in fact the rates are also constantly changing works quite similarly to how the stock market fluctuates.
Great article. I thought the content very beneficial. Loved the method you explained the content.
mexican rx online: best online pharmacies in mexico – buying prescription drugs in mexico
http://indiapharmacy.shop/# indian pharmacy
Online medicine home delivery: Indian pharmacy international shipping – indian pharmacy paypal
top rated ed pills: Cheapest online ED treatment – low cost ed meds
Whether due to human error, technical glitches, or malicious activities, the risk of losing access to your digital assets looms large.
ed medication online: online ed prescription same-day – best ed medication online
I love it when people get together and share ideas. Great blog, stick with it!
homosexual porn
These are all valid advantages but then again the risk of making the wrong and unguided decision will always be there.
Spot on with this write-up, I really believe this site needs a lot more attention. I’ll probably be back again to see more, thanks for the info.
There are a number of good reasons for risk assessment.
ed pills cheap: online ed prescription same-day – top rated ed pills
http://mexicopharmacy.win/# mexican mail order pharmacies
I’d like to thank you for the efforts you’ve put in writing this website. I’m hoping to check out the same high-grade content by you in the future as well. In truth, your creative writing abilities has motivated me to get my own site now 😉
how to get ed meds online: online ed prescription same-day – ed rx online
buy ed pills online: ed pills online – online ed meds
п»їed pills online: ED meds online with insurance – where to get ed pills
online casino
This web site certainly has all of the info I needed concerning this subject and didn’t know who to ask.
http://indiapharmacy.shop/# Online medicine order
http://indiapharmacy.shop/# mail order pharmacy india
Nice post. I learn something new and challenging on sites I stumbleupon everyday. It will always be useful to read through content from other authors and practice something from other websites.
online ed pharmacy: online ed prescription same-day – erectile dysfunction pills online
best online pharmacy india: Indian pharmacy international shipping – indianpharmacy com
pharmacy website india: Online medicine home delivery – india online pharmacy
erection pills online: cheap ed pills online – erectile dysfunction online
https://edpillpharmacy.store/# cheapest ed medication
discount ed pills
https://indiapharmacy.shop/# online shopping pharmacy india
http://indiapharmacy.shop/# indian pharmacies safe
Genuinely enjoyed perusing this article. It’s very well-written and packed with helpful insight. Thank you for sharing this.
http://mexicopharmacy.win/# medication from mexico pharmacy
discount ed pills
https://edpillpharmacy.store/# cheapest erectile dysfunction pills
ed meds cheap
what is the cheapest ed medication: erection pills online – buy erectile dysfunction treatment
I need to to thank you for this excellent read!! I definitely loved every bit of it. I have you saved as a favorite to check out new things you post…
ed prescription online: Cheapest online ED treatment – online ed drugs
medication from mexico pharmacy: Mexico pharmacy online – mexican rx online
This article is fantastic. I gained a lot from going through it. The content is very informative and structured.
https://indiapharmacy.shop/# top 10 pharmacies in india