上一期我们介绍了外观设计,这把我们聊聊让进度条跟随播放进度走
目录
预期效果
准备
- 在此之前,你需要有以下基础:
- 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>
- 最终效果:
- 默认是静音的,可以点击播放试试
Oh my goodness! an excellent article dude. Thanks a ton However My business is experiencing problem with ur rss . Do not know why Struggle to join it. Will there be everyone finding identical rss issue? Anyone who knows kindly respond. Thnkx
There is noticeably a lot of money to know about this. I assume you made particular nice points in features also.
This is a proper blog for everyone who hopes to learn about this topic. You are aware of much its almost tricky to argue on hand (not that I really would want…HaHa). You actually put a brand new spin on a topic thats been discussed for some time. Great stuff, just excellent!
you can get some free catalogs over the internet easily if you just search on google’
Hey there! I just wanted to ask if you ever have any problems with hackers? My last blog (wordpress) was hacked and I ended up losing a few months of hard work due to no back up. Do you have any solutions to prevent hackers?
Thanks for the feature again! I guess it means I am doing a lot of things right.
Howdy, i read your blog occasionally and i own a similar one and i was just curious if you get a lot of spam feedback? If so how do you reduce it, any plugin or anything you can advise? I get so much lately it’s driving me mad so any support is very much appreciated.
Writing a great article takes commitment and pride in one’s work. It’s apparent that this writer has it together. Each point is well formatted. The grammar and spelling is excellent.
Can I simply say what a reduction to search out someone who actually is aware of what theyre speaking about on the internet. You definitely know easy methods to bring an issue to gentle and make it important. More folks must read this and understand this facet of the story. I cant believe youre not more widespread because you undoubtedly have the gift.
This website online can be a stroll-by means of for all the data you needed about this and didn’t know who to ask. Glimpse here, and you’ll undoubtedly uncover it.
pharmacie en ligne livraison europe: pharmacie en ligne fiable – п»їpharmacie en ligne france
Viagra pas cher livraison rapide france: Viagra generique en pharmacie – Viagra pas cher livraison rapide france
Pharmacie sans ordonnance: acheter mГ©dicament en ligne sans ordonnance – pharmacie en ligne france livraison belgique
pharmacie en ligne france fiable: cialis sans ordonnance – Pharmacie Internationale en ligne
Viagra vente libre allemagne: Acheter du Viagra sans ordonnance – Viagra homme prix en pharmacie sans ordonnance
vente de mГ©dicament en ligne: pharmacie en ligne pas cher – pharmacie en ligne
trouver un mГ©dicament en pharmacie: levitra generique sites surs – pharmacie en ligne pas cher
pharmacie en ligne avec ordonnance: kamagra 100mg prix – pharmacie en ligne pas cher
pharmacie en ligne france livraison belgique: Cialis sans ordonnance 24h – pharmacie en ligne
Viagra pas cher livraison rapide france: Viagra sans ordonnance 24h – Viagra sans ordonnance 24h Amazon
pharmacie en ligne livraison europe: cialis sans ordonnance – pharmacie en ligne
pharmacie en ligne sans ordonnance: achat kamagra – pharmacies en ligne certifiГ©es
pharmacies en ligne certifiГ©es: levitra generique – trouver un mГ©dicament en pharmacie
Viagra sans ordonnance 24h suisse: Viagra generique en pharmacie – Viagra gГ©nГ©rique sans ordonnance en pharmacie
vente de mГ©dicament en ligne: Levitra 20mg prix en pharmacie – pharmacie en ligne fiable
pharmacie en ligne avec ordonnance: kamagra pas cher – Pharmacie en ligne livraison Europe
Achat mГ©dicament en ligne fiable: levitra en ligne – pharmacie en ligne sans ordonnance
pharmacie en ligne fiable: levitra en ligne – vente de mГ©dicament en ligne
Achat mГ©dicament en ligne fiable: kamagra pas cher – pharmacie en ligne france pas cher
Pharmacie Internationale en ligne: kamagra gel – acheter mГ©dicament en ligne sans ordonnance
pharmacie en ligne france pas cher: Acheter Cialis 20 mg pas cher – pharmacie en ligne france pas cher
You consistently produce high-quality content that is both informative and enjoyable to read. This post was no exception. Keep it up!pulsepeak
Viagra vente libre allemagne: Viagra generique en pharmacie – Viagra gГ©nГ©rique sans ordonnance en pharmacie
pharmacie en ligne fiable: Medicaments en ligne livres en 24h – pharmacie en ligne france livraison belgique
Viagra gГ©nГ©rique sans ordonnance en pharmacie: Viagra pas cher livraison rapide france – Prix du Viagra en pharmacie en France
vente de mГ©dicament en ligne: pharmacie en ligne pas cher – pharmacie en ligne france fiable
https://viaenligne.com/# Viagra générique sans ordonnance en pharmacie
Viagra sans ordonnance 24h suisse: viagra en ligne – SildГ©nafil Teva 100 mg acheter
pharmacie en ligne france livraison internationale: cialis prix – acheter mГ©dicament en ligne sans ordonnance
pharmacie en ligne france livraison belgique: cialis prix – Pharmacie Internationale en ligne
Viagra 100 mg sans ordonnance: viagra en ligne – SildГ©nafil 100mg pharmacie en ligne
pharmacie en ligne france livraison belgique: kamagra 100mg prix – pharmacie en ligne france pas cher
pharmacie en ligne: Levitra pharmacie en ligne – pharmacie en ligne france pas cher
https://viaenligne.com/# Meilleur Viagra sans ordonnance 24h
Quand une femme prend du Viagra homme: Viagra generique en pharmacie – Viagra femme sans ordonnance 24h
pharmacies en ligne certifiГ©es: Levitra pharmacie en ligne – pharmacie en ligne france livraison internationale
Viagra pas cher livraison rapide france: Viagra sans ordonnance 24h – Viagra pas cher livraison rapide france
pharmacie en ligne france livraison belgique: pharmacie en ligne pas cher – pharmacie en ligne sans ordonnance
pharmacie en ligne pas cher: achat kamagra – Pharmacie en ligne livraison Europe
Achat mГ©dicament en ligne fiable: kamagra oral jelly – acheter mГ©dicament en ligne sans ordonnance