上一期我们介绍了外观设计,这把我们聊聊让进度条跟随播放进度走
目录
预期效果
准备
- 在此之前,你需要有以下基础:
- 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://indiapharmacy.shop/# best india pharmacy
get ed prescription online
untrustable
buying from online mexican pharmacy: Mexico pharmacy online – mexican drugstore online
http://indiapharmacy.shop/# reputable indian online pharmacy
get ed meds today
http://indiapharmacy.shop/# buy prescription drugs from india
ed pills cheap
https://mexicopharmacy.win/# buying prescription drugs in mexico
ed meds cheap
get ed meds today: cheap ed pills online – cheapest online ed meds
http://edpillpharmacy.store/# ed prescriptions online
https://indiapharmacy.shop/# indianpharmacy com
indian pharmacy online: Online pharmacy USA – Online medicine home delivery
buying prescription drugs in mexico online: Mexico pharmacy online – mexico drug stores pharmacies
http://mexicopharmacy.win/# buying prescription drugs in mexico
online erectile dysfunction
http://edpillpharmacy.store/# online erectile dysfunction
erectile dysfunction medication online
http://edpillpharmacy.store/# ed medications cost
ed online meds
erectile dysfunction online prescription: Cheapest online ED treatment – buy ed pills online
https://edpillpharmacy.store/# cheapest ed treatment
ed meds by mail
homosexual porn
http://edpillpharmacy.store/# online ed pills
I blog frequently and I seriously thank you for your information. This article has really peaked my interest. I will take a note of your website and keep checking for new details about once per week. I opted in for your RSS feed too.
mexico pharmacies prescription drugs: mexico pharmacy win – mexican mail order pharmacies
https://mexicopharmacy.win/# mexican drugstore online
cheapest online ed treatment
https://mexicopharmacy.win/# medication from mexico pharmacy
erectile dysfunction pills for sale
http://mexicopharmacy.win/# mexico pharmacies prescription drugs
where can i buy erectile dysfunction pills
purple pharmacy mexico price list: Certified Mexican pharmacy – mexican rx online
buying from online mexican pharmacy: Certified Mexican pharmacy – reputable mexican pharmacies online
100 mg viagra lowest price: Viagra without a doctor prescription – viagra without doctor prescription
lesbian porn
https://sildenafil.llc/# buy viagra professional
Spot on with this write-up, I honestly believe that this web site needs a lot more attention. I’ll probably be returning to read more, thanks for the advice.
buy viagra pills: Buy Viagra online cheap – cialis vs viagra
how long does cialis last: Buy Cialis online – cialis mail order
buy viagra online: Cheap generic Viagra – 100mg viagra without a doctor prescription
https://sildenafil.llc/# viagra pills
https://sildenafil.llc/# viagra dosage recommendations
viagra for women: Viagra without a doctor prescription – over the counter alternative to viagra
Pretty! This has been an extremely wonderful post. Thank you for supplying this info.
viagra coupon: Buy Viagra online in USA – buy generic viagra online
lesbian porn
https://tadalafil.auction/# cialis going over the counter
buy viagra order: buy sildenafil online usa – viagra professional
viagra cost: Viagra online price – how does viagra work
This is a topic that is near to my heart… Take care! Where can I find the contact details for questions?
I was able to find good info from your articles.
generic cialis no prescription australia: Buy Tadalafil 20mg – cialis buy
https://tadalafil.auction/# how to get doctor to prescribe cialis
cialis for sale canada: Buy Tadalafil 20mg – how to buy generic cialis online
real viagra without a doctor prescription: Cheap Viagra online – viagra dosage
can i take cialis with daxpoteine: cialis without a doctor prescription – cialis/dapoxetine with overnight ship
online cialis australia: cialis nz – where can i buy cialis 20mg
This excellent website truly has all of the information I needed concerning this subject and didn’t know who to ask.