[vue3]audio音乐进度条(二)跟随播放进度

/ 6,324评论 / 25298阅读 / 2点赞

上一期我们介绍了外观设计,这把我们聊聊让进度条跟随播放进度走

预期效果


准备


实现

<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>
<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>
<!-- 引入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>
  1. Richardfrota说道:

    neurontin price uk: neurontin capsules 100mg – how much is generic neurontin

  2. CharlesGib说道:

    zithromax 500 mg lowest price pharmacy online: purchase zithromax online – zithromax antibiotic

  3. Billyeroge说道:

    https://amoxila.pro/# where to buy amoxicillin over the counter

  4. HenryIsona说道:

    prednisone tablets india: can i buy prednisone online without prescription – brand prednisone

  5. Billyeroge说道:

    http://prednisoned.online/# prednisone 10 mg canada

  6. Richardfrota说道:

    neurontin 100 mg tablets: neurontin 100 mg – buy gabapentin

  7. Billyeroge说道:

    https://doxycyclinea.online/# buy doxycycline online

  8. HenryIsona说道:

    doxycycline 100mg dogs: doxycycline 100mg online – doxycycline hyc

  9. MarvinMek说道:

    cortisol prednisone buy 40 mg prednisone buy prednisone online no script

  10. MarvinMek说道:

    buy zithromax can you buy zithromax online zithromax over the counter

  11. CharlesGib说道:

    buy prednisone online australia: 10 mg prednisone tablets – where to buy prednisone uk

  12. HenryIsona说道:

    amoxicillin 500: buy amoxicillin canada – cost of amoxicillin prescription

  13. MarvinMek说道:

    buy neurontin online no prescription neurontin 100 cost of neurontin 100mg

  14. HenryIsona说道:

    neurontin 600 mg coupon: cheap neurontin online – buy neurontin online uk

  15. Billyeroge说道:

    http://gabapentinneurontin.pro/# how much is neurontin pills

  16. Richardfrota说道:

    zithromax 500 mg lowest price online: how to get zithromax over the counter – buy zithromax online

  17. CharlesGib说道:

    buy prednisone no prescription: prednisone pills 10 mg – online prednisone

  18. MarvinMek说道:

    where to purchase doxycycline doxycycline 100 mg purchase doxycycline online

  19. Billyeroge说道:

    http://amoxila.pro/# amoxicillin online purchase

  20. Billyeroge说道:

    https://gabapentinneurontin.pro/# cost of neurontin 100mg

  21. MarvinMek说道:

    generic neurontin cost neurontin canada online brand neurontin 100 mg canada

  22. Richardfrota说道:

    zithromax online usa: zithromax prescription online – zithromax 500 mg lowest price online

  23. HenryIsona说道:

    prednisone 20 mg prices: prednisone online – buying prednisone without prescription

  24. CharlesGib说道:

    zithromax prescription online: zithromax 250 price – zithromax 250 mg tablet price

  25. HenryIsona说道:

    amoxicillin 500 mg tablet: amoxicillin without a prescription – amoxicillin 500mg capsules antibiotic

  26. MarvinMek说道:

    prednisone steroids prednisone 15 mg daily 50mg prednisone tablet

  27. Donaldkenty说道:

    canadian pharmacy discount coupon: pharm world store – no prescription required pharmacy

  28. Williamfug说道:

    no prescription pharmacy paypal: cheapest pharmacy – legit non prescription pharmacies

  29. DavidTaK说道:

    medication from mexico pharmacy mexico drug stores pharmacies mexico pharmacy

  30. DavidTaK说道:

    top 10 online pharmacy in india online pharmacy india top 10 pharmacies in india

  31. Felipelam说道:

    http://pharmnoprescription.icu/# pills no prescription

  32. Williamfug说道:

    mexican pharmacy: mexican online pharmacies prescription drugs – mexico pharmacy

  33. Felipelam说道:

    https://pharmnoprescription.icu/# legitimate online pharmacy no prescription

  34. Felipelam说道:

    https://pharmindia.online/# indian pharmacies safe

  35. Williamfug说道:

    recommended canadian pharmacies: canadian pharmacy prices – best online canadian pharmacy

  36. DavidTaK说道:

    canadapharmacyonline com best mail order pharmacy canada canadian pharmacy meds review

  37. Jeromeviaph说道:

    https://pharmworld.store/# cheapest pharmacy to fill prescriptions with insurance

  38. DonaldtAg说道:

    indian pharmacy: online pharmacy india – india pharmacy

  39. Jeromeviaph说道:

    https://pharmcanada.shop/# best online canadian pharmacy

  40. Williamfug说道:

    canada pharmacy online no prescription: non prescription online pharmacy india – canadian prescription prices

  41. DonaldtAg说道:

    buy drugs online no prescription: canadian prescription – how to order prescription drugs from canada

  42. DavidTaK说道:

    canadian mail order prescriptions canada prescription drugs online online meds no prescription

  43. Williamfug说道:

    canadian pharmacy no prescription needed: canadian rx prescription drugstore – buy medication online with prescription

  44. DavidTaK说道:

    buy medicines online in india indian pharmacy п»їlegitimate online pharmacies india

  45. Felipelam说道:

    http://pharmworld.store/# canadian pharmacy world coupons

  46. Felipelam说道:

    https://pharmindia.online/# top online pharmacy india

  47. Williamfug说道:

    indianpharmacy com: Online medicine order – indian pharmacy

  48. DavidTaK说道:

    rxpharmacycoupons online pharmacy drugstore com online pharmacy prescription drugs

  49. DonaldtAg说道:

    buying prescription drugs from canada online: mexican prescription drugs online – online meds without prescription

  50. Donaldkenty说道:

    no prescription medicines: canadian pharmacy without prescription – online pharmacy that does not require a prescription

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注