上一期我们介绍了外观设计,这把我们聊聊让进度条跟随播放进度走
目录
预期效果
准备
- 在此之前,你需要有以下基础:
- 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>
- 最终效果:
- 默认是静音的,可以点击播放试试
https://onlinepharmacyworld.shop/# online pharmacy discount code
https://onlinepharmacyworld.shop/# legit non prescription pharmacies
online pharmacy no prescription: canada prescription – best online pharmacy without prescriptions
http://edpill.top/# online ed medications
mexican prescription drugs online: canada drugs no prescription – no prescription drugs
canadian pharmacy without prescription legal online pharmacy coupon code pharmacy coupons
http://onlinepharmacyworld.shop/# canadian pharmacy without prescription
http://onlinepharmacyworld.shop/# promo code for canadian pharmacy meds
erectile dysfunction pills online: ed pills – cheap ed meds
http://onlinepharmacyworld.shop/# canadian pharmacy world coupon
online pharmacy without prescription: buy medication online with prescription – cheap drugs no prescription
where can i buy erectile dysfunction pills where can i buy erectile dysfunction pills cheap ed pills
https://medicationnoprescription.pro/# prescription drugs canada
canadian online pharmacy no prescription: canadian pharmacy coupon – foreign pharmacy no prescription
http://medicationnoprescription.pro/# discount prescription drugs canada
http://edpill.top/# ed medications cost
best online prescription: canada prescriptions by mail – best no prescription online pharmacies
http://onlinepharmacyworld.shop/# drugstore com online pharmacy prescription drugs
https://onlinepharmacyworld.shop/# canadian pharmacy no prescription
can i buy generic clomid: how can i get generic clomid – where can i buy clomid without prescription
purchase zithromax online: zithromax price canada – can you buy zithromax over the counter in canada
https://azithromycina.pro/# how to buy zithromax online
prednisone buying: prednisone buying – price of prednisone 5mg
buy amoxicillin 500mg uk: where can you buy amoxicillin over the counter – medicine amoxicillin 500
https://stromectola.top/# ivermectin cream 5%
ivermectin 10 ml: ivermectin coronavirus – stromectol 0.5 mg
can you get cheap clomid prices: where to buy clomid no prescription – can i get generic clomid prices
https://prednisonea.store/# prednisone in mexico
where to buy prednisone uk: how can i get prednisone – prednisone tablets canada
https://azithromycina.pro/# buy generic zithromax no prescription
generic clomid pill: cheap clomid prices – where to buy clomid without a prescription
https://clomida.pro/# where can i buy cheap clomid without insurance
where to get generic clomid pill: clomid pill – buying generic clomid prices
amoxicillin 500 mg online: amoxicillin 500 mg tablet – amoxicillin 500mg capsules
where to buy generic clomid prices: can i buy generic clomid now – how can i get cheap clomid without insurance
can i buy cheap clomid: where to buy generic clomid without insurance – where can i get cheap clomid without insurance
https://clomida.pro/# where can i buy generic clomid now
tamoxifen depression: tamoxifen dose – nolvadex steroids
order doxycycline: how to order doxycycline – doxycycline hyclate
diflucan rx online: diflucan 200 mg over the counter – buy diflucan over the counter
Cytotec 200mcg price: buy cytotec over the counter – purchase cytotec
online rx diflucan: can i buy diflucan from canada – buying diflucan over the counter
buy misoprostol over the counter: buy cytotec over the counter – Misoprostol 200 mg buy online
https://nolvadex.icu/# does tamoxifen make you tired
diflucan 150mg: where to buy diflucan in uk – diflucan 6
buy cytotec online fast delivery: cytotec online – purchase cytotec
alternatives to tamoxifen: nolvadex generic – tamoxifen endometrium
Cytotec 200mcg price: Abortion pills online – buy cytotec pills
how to get diflucan online: diflucan online cheap – diflucan uk price
nolvadex for pct: buy nolvadex online – arimidex vs tamoxifen bodybuilding