上一期我们介绍了外观设计,这把我们聊聊让进度条跟随播放进度走
目录
预期效果
准备
- 在此之前,你需要有以下基础:
- 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>
- 最终效果:
- 默认是静音的,可以点击播放试试
cost of cheap propecia no prescription: buying generic propecia without dr prescription – buy propecia online
cost propecia without insurance: order generic propecia no prescription – generic propecia
buying propecia no prescription: order cheap propecia prices – buy propecia now
zithromax prescription in canada: zithromax 1000 mg online – zithromax order online uk
http://nolvadexbestprice.pro/# tamoxifen and grapefruit
zithromax 500mg price: where can i buy zithromax in canada – buy zithromax online fast shipping
prednisone prescription online: no prescription online prednisone – 1 mg prednisone cost
tamoxifen lawsuit: nolvadex online – does tamoxifen cause joint pain
tamoxifen side effects forum: low dose tamoxifen – nolvadex gynecomastia
zithromax 500 mg: zithromax capsules australia – zithromax generic cost
prednisone 250 mg: prednisone brand name india – buying prednisone without prescription
cost of generic zithromax: can you buy zithromax over the counter – zithromax prescription
tamoxifen 20 mg tablet: tamoxifen rash – tamoxifen and bone density
https://prednisonebestprice.pro/# prednisone 10mg prices
femara vs tamoxifen: tamoxifen depression – tamoxifen vs clomid
zithromax capsules zithromax 500mg order zithromax without prescription
where can i buy zithromax capsules zithromax prescription zithromax 1000 mg online
tamoxifen breast cancer tamoxifen hair loss tamoxifen and weight loss
order propecia for sale: cost generic propecia online – get propecia
https://prednisonebestprice.pro/# prednisone 10mg buy online
http://propeciabestprice.pro/# cheap propecia no prescription
cost generic propecia without insurance: cost of generic propecia without dr prescription – cost of cheap propecia pill
Next time I read a blog, Hopefully it won’t fail me as much as this particular one. After all, I know it was my choice to read through, but I really thought you would have something interesting to say. All I hear is a bunch of whining about something that you could possibly fix if you weren’t too busy looking for attention.
what is tamoxifen used for: tamoxifen benefits – tamoxifen 20 mg
raloxifene vs tamoxifen tamoxifen benefits nolvadex online
http://cytotecbestprice.pro/# buy cytotec
buy cytotec over the counter: Abortion pills online – Abortion pills online
zithromax online no prescription: zithromax for sale cheap – zithromax 250
buy cytotec pills: cytotec buy online usa – Cytotec 200mcg price
cortisol prednisone buying prednisone on line prednisone 10 mg tablets
tamoxifen for men tamoxifen premenopausal tamoxifen alternatives premenopausal
cytotec pills buy online cytotec buy online usa purchase cytotec
http://prednisonebestprice.pro/# buy prednisone 10mg online
What do some people say happened to Walt Disney’s body after he died?
get generic propecia without dr prescription: generic propecia pills – cost of propecia without rx
zithromax prescription online zithromax 500mg price in india zithromax capsules australia
https://prednisonebestprice.pro/# prednisone for sale in canada
http://prednisonebestprice.pro/# 50 mg prednisone tablet
http://zithromaxbestprice.pro/# zithromax online usa no prescription
https://cytotecbestprice.pro/# order cytotec online
cytotec abortion pill: buy misoprostol over the counter – Misoprostol 200 mg buy online
http://zithromaxbestprice.pro/# where can i get zithromax over the counter
hacklink
http://nolvadexbestprice.pro/# tamoxifen dosage
prednisone nz: prednisone without prescription.net – 25 mg prednisone
cost cheap propecia prices: propecia no prescription – cost propecia online
https://nolvadexbestprice.pro/# nolvadex half life
buying cheap propecia prices buy propecia now get propecia no prescription
Cytotec 200mcg price cytotec online order cytotec online
http://cytotecbestprice.pro/# buy cytotec over the counter