上一期我们介绍了外观设计,这把我们聊聊让进度条跟随播放进度走
目录
预期效果
准备
- 在此之前,你需要有以下基础:
- 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>
- 最终效果:
- 默认是静音的,可以点击播放试试
mexico pharmacies prescription drugs cmq pharma mexican pharmacy buying from online mexican pharmacy
mexico drug stores pharmacies online mexican pharmacy mexico pharmacy
mexican online pharmacies prescription drugs mexican pharmacy online mexican pharmacy
mexico drug stores pharmacies cmq pharma mexican border pharmacies shipping to usa
mexico pharmacy cmq pharma mexican pharmacy п»їbest mexican online pharmacies
mexican pharmaceuticals online cmq mexican pharmacy online mexican pharmaceuticals online
크레이지타임 에볼루션
mexican pharmaceuticals online
https://cmqpharma.online/# mexican rx online
mexican rx online
mexican rx online medicine in mexico pharmacies buying prescription drugs in mexico online
medicine in mexico pharmacies mexican online pharmacy best online pharmacies in mexico
건담 에볼루션 섭종
п»їbest mexican online pharmacies mexican pharmacy online buying from online mexican pharmacy
mexican mail order pharmacies
https://cmqpharma.online/# best online pharmacies in mexico
best online pharmacies in mexico
buying prescription drugs in mexico online mexican online pharmacies prescription drugs mexican online pharmacies prescription drugs
purple pharmacy mexico price list: cmq mexican pharmacy online – reputable mexican pharmacies online
buying from online mexican pharmacy: cmq pharma mexican pharmacy – buying from online mexican pharmacy
mexican rx online cmqpharma.com buying prescription drugs in mexico
there is no day in the month that i do not want to visit your blog.
medicine in mexico pharmacies cmqpharma.com mexican mail order pharmacies
mexican drugstore online
https://cmqpharma.online/# mexican drugstore online
mexican mail order pharmacies
buying from online mexican pharmacy mexican pharmacy mexican pharmaceuticals online
Very great post. I simply stumbled upon your weblog and wanted to say that I’ve truly enjoyed surfing around your weblog posts. In any case I will be subscribing for your rss feed and I hope you write once more very soon!
mexico drug stores pharmacies mexican pharmacy mexico drug stores pharmacies
mexican rx online: mexico pharmacy – п»їbest mexican online pharmacies
purple pharmacy mexico price list: online mexican pharmacy – medication from mexico pharmacy
mexican mail order pharmacies cmq pharma reputable mexican pharmacies online
reputable mexican pharmacies online cmq mexican pharmacy online mexico pharmacies prescription drugs
I want to convey my passion for your generosity giving support to men and women that must have help with the concern. Your real dedication to passing the solution up and down had become rather invaluable and have frequently permitted folks much like me to achieve their targets. Your personal valuable guidelines means a great deal to me and far more to my peers. With thanks; from everyone of us.
medication from mexico pharmacy mexican online pharmacy medication from mexico pharmacy
mexican rx online cmqpharma.com mexico pharmacy
All the great facts about News became valuable to most of people.
mexican rx online
https://cmqpharma.online/# mexican rx online
buying prescription drugs in mexico
https://cmqpharma.online/# mexican drugstore online
buying from online mexican pharmacy
https://cmqpharma.com/# mexican mail order pharmacies
pharmacies in mexico that ship to usa
buying prescription drugs in mexico mexico pharmacy mexican drugstore online
https://northern-doctors.org/# buying from online mexican pharmacy
п»їbest mexican online pharmacies: mexican northern doctors – mexican pharmacy
mexican pharmacy: Mexico pharmacy that ship to usa – medication from mexico pharmacy
reputable mexican pharmacies online northern doctors pharmacy mexican border pharmacies shipping to usa
http://northern-doctors.org/# mexico drug stores pharmacies
https://northern-doctors.org/# buying prescription drugs in mexico
reputable mexican pharmacies online: mexican online pharmacies prescription drugs – mexico drug stores pharmacies
buying prescription drugs in mexico online: mexican pharmacy northern doctors – mexican drugstore online
mexican drugstore online: Mexico pharmacy that ship to usa – mexican pharmaceuticals online
mexico drug stores pharmacies: mexican pharmacy northern doctors – medicine in mexico pharmacies
https://northern-doctors.org/# mexican pharmacy
https://northern-doctors.org/# buying prescription drugs in mexico online
mexican pharmaceuticals online: Mexico pharmacy that ship to usa – mexican mail order pharmacies
buying prescription drugs in mexico mexican pharmacy northern doctors mexican drugstore online
mexican drugstore online: mexican pharmacy northern doctors – purple pharmacy mexico price list