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

/ 1,792评论 / 7959阅读 / 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. MatthewDoolo说道:

    erectile dysfunction pills online: ed pills – cheap ed meds

  2. Armandosed说道:

    http://onlinepharmacyworld.shop/# canadian pharmacy world coupon

  3. AustinWhoto说道:

    online pharmacy without prescription: buy medication online with prescription – cheap drugs no prescription

  4. PhilipBup说道:

    where can i buy erectile dysfunction pills where can i buy erectile dysfunction pills cheap ed pills

  5. Armandosed说道:

    https://medicationnoprescription.pro/# prescription drugs canada

  6. MatthewDoolo说道:

    canadian online pharmacy no prescription: canadian pharmacy coupon – foreign pharmacy no prescription

  7. HarveyBeemi说道:

    http://medicationnoprescription.pro/# discount prescription drugs canada

  8. Armandosed说道:

    http://edpill.top/# ed medications cost

  9. MatthewDoolo说道:

    best online prescription: canada prescriptions by mail – best no prescription online pharmacies

  10. HarveyBox说道:

    http://onlinepharmacyworld.shop/# drugstore com online pharmacy prescription drugs

  11. Armandosed说道:

    https://onlinepharmacyworld.shop/# canadian pharmacy no prescription

  12. DomenicDobby说道:

    can i buy generic clomid: how can i get generic clomid – where can i buy clomid without prescription

  13. BryanSturf说道:

    purchase zithromax online: zithromax price canada – can you buy zithromax over the counter in canada

  14. BrainSaw说道:

    https://azithromycina.pro/# how to buy zithromax online

  15. MichaelPycle说道:

    prednisone buying: prednisone buying – price of prednisone 5mg

  16. MichaelPycle说道:

    buy amoxicillin 500mg uk: where can you buy amoxicillin over the counter – medicine amoxicillin 500

  17. BrainSaw说道:

    https://stromectola.top/# ivermectin cream 5%

  18. MichaelPycle说道:

    ivermectin 10 ml: ivermectin coronavirus – stromectol 0.5 mg

  19. BryanSturf说道:

    can you get cheap clomid prices: where to buy clomid no prescription – can i get generic clomid prices

  20. BrainSaw说道:

    https://prednisonea.store/# prednisone in mexico

  21. MichaelPycle说道:

    where to buy prednisone uk: how can i get prednisone – prednisone tablets canada

  22. Josephtrink说道:

    https://azithromycina.pro/# buy generic zithromax no prescription

  23. MichaelPycle说道:

    generic clomid pill: cheap clomid prices – where to buy clomid without a prescription

  24. BrainSaw说道:

    https://clomida.pro/# where can i buy cheap clomid without insurance

  25. DomenicDobby说道:

    where to get generic clomid pill: clomid pill – buying generic clomid prices

  26. BryanSturf说道:

    amoxicillin 500 mg online: amoxicillin 500 mg tablet – amoxicillin 500mg capsules

  27. MichaelPycle说道:

    where to buy generic clomid prices: can i buy generic clomid now – how can i get cheap clomid without insurance

  28. MichaelPycle说道:

    can i buy cheap clomid: where to buy generic clomid without insurance – where can i get cheap clomid without insurance

  29. Josephtrink说道:

    https://clomida.pro/# where can i buy generic clomid now

  30. Williamzew说道:

    tamoxifen depression: tamoxifen dose – nolvadex steroids

  31. RussellVeila说道:

    order doxycycline: how to order doxycycline – doxycycline hyclate

  32. RussellVeila说道:

    diflucan rx online: diflucan 200 mg over the counter – buy diflucan over the counter

  33. RussellVeila说道:

    Cytotec 200mcg price: buy cytotec over the counter – purchase cytotec

  34. Williamzew说道:

    online rx diflucan: can i buy diflucan from canada – buying diflucan over the counter

  35. JamesSew说道:

    buy misoprostol over the counter: buy cytotec over the counter – Misoprostol 200 mg buy online

  36. Archierut说道:

    https://nolvadex.icu/# does tamoxifen make you tired

  37. RussellVeila说道:

    diflucan 150mg: where to buy diflucan in uk – diflucan 6

  38. RussellVeila说道:

    buy cytotec online fast delivery: cytotec online – purchase cytotec

  39. RussellVeila说道:

    alternatives to tamoxifen: nolvadex generic – tamoxifen endometrium

  40. Williamzew说道:

    Cytotec 200mcg price: Abortion pills online – buy cytotec pills

  41. RussellVeila说道:

    how to get diflucan online: diflucan online cheap – diflucan uk price

  42. RussellVeila说道:

    nolvadex for pct: buy nolvadex online – arimidex vs tamoxifen bodybuilding

回复 uttenly 取消回复

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