上一期我们介绍了外观设计,这把我们聊聊让进度条跟随播放进度走
目录
预期效果
准备
- 在此之前,你需要有以下基础:
- 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>
- 最终效果:
- 默认是静音的,可以点击播放试试
neurontin price uk: neurontin capsules 100mg – how much is generic neurontin
zithromax 500 mg lowest price pharmacy online: purchase zithromax online – zithromax antibiotic
https://amoxila.pro/# where to buy amoxicillin over the counter
prednisone tablets india: can i buy prednisone online without prescription – brand prednisone
http://prednisoned.online/# prednisone 10 mg canada
neurontin 100 mg tablets: neurontin 100 mg – buy gabapentin
https://doxycyclinea.online/# buy doxycycline online
doxycycline 100mg dogs: doxycycline 100mg online – doxycycline hyc
cortisol prednisone buy 40 mg prednisone buy prednisone online no script
buy zithromax can you buy zithromax online zithromax over the counter
buy prednisone online australia: 10 mg prednisone tablets – where to buy prednisone uk
amoxicillin 500: buy amoxicillin canada – cost of amoxicillin prescription
buy neurontin online no prescription neurontin 100 cost of neurontin 100mg
neurontin 600 mg coupon: cheap neurontin online – buy neurontin online uk
http://gabapentinneurontin.pro/# how much is neurontin pills
zithromax 500 mg lowest price online: how to get zithromax over the counter – buy zithromax online
buy prednisone no prescription: prednisone pills 10 mg – online prednisone
where to purchase doxycycline doxycycline 100 mg purchase doxycycline online
http://amoxila.pro/# amoxicillin online purchase
https://gabapentinneurontin.pro/# cost of neurontin 100mg
generic neurontin cost neurontin canada online brand neurontin 100 mg canada
zithromax online usa: zithromax prescription online – zithromax 500 mg lowest price online
prednisone 20 mg prices: prednisone online – buying prednisone without prescription
zithromax prescription online: zithromax 250 price – zithromax 250 mg tablet price
amoxicillin 500 mg tablet: amoxicillin without a prescription – amoxicillin 500mg capsules antibiotic
prednisone steroids prednisone 15 mg daily 50mg prednisone tablet
canadian pharmacy discount coupon: pharm world store – no prescription required pharmacy
no prescription pharmacy paypal: cheapest pharmacy – legit non prescription pharmacies
medication from mexico pharmacy mexico drug stores pharmacies mexico pharmacy
top 10 online pharmacy in india online pharmacy india top 10 pharmacies in india
http://pharmnoprescription.icu/# pills no prescription
mexican pharmacy: mexican online pharmacies prescription drugs – mexico pharmacy
https://pharmnoprescription.icu/# legitimate online pharmacy no prescription
https://pharmindia.online/# indian pharmacies safe
recommended canadian pharmacies: canadian pharmacy prices – best online canadian pharmacy
canadapharmacyonline com best mail order pharmacy canada canadian pharmacy meds review
https://pharmworld.store/# cheapest pharmacy to fill prescriptions with insurance
indian pharmacy: online pharmacy india – india pharmacy
https://pharmcanada.shop/# best online canadian pharmacy
canada pharmacy online no prescription: non prescription online pharmacy india – canadian prescription prices
buy drugs online no prescription: canadian prescription – how to order prescription drugs from canada
canadian mail order prescriptions canada prescription drugs online online meds no prescription
canadian pharmacy no prescription needed: canadian rx prescription drugstore – buy medication online with prescription
buy medicines online in india indian pharmacy п»їlegitimate online pharmacies india
http://pharmworld.store/# canadian pharmacy world coupons
https://pharmindia.online/# top online pharmacy india
indianpharmacy com: Online medicine order – indian pharmacy
rxpharmacycoupons online pharmacy drugstore com online pharmacy prescription drugs
buying prescription drugs from canada online: mexican prescription drugs online – online meds without prescription
no prescription medicines: canadian pharmacy without prescription – online pharmacy that does not require a prescription