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

/ 6,316评论 / 25276阅读 / 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. Tylerreunk说道:

    http://kamagra.win/# п»їkamagra

  2. Elmersoalf说道:

    Viagra tablet online Buy Viagra online cheap buy Viagra online

  3. DavidBiolo说道:

    https://cenforce.pro/# cheapest cenforce

  4. Georgefrege说道:

    Purchase Cenforce Online: cenforce.pro – order cenforce

  5. Elmersoalf说道:

    sildenafil oral jelly 100mg kamagra kamagra pills Kamagra 100mg price

  6. Jamesexite说道:

    Vardenafil online prescription: levitrav.store – Cheap Levitra online

  7. Georgefrege说道:

    Buy Cenforce 100mg Online: Purchase Cenforce Online – cenforce for sale

  8. DavidBiolo说道:

    http://cenforce.pro/# cheapest cenforce

  9. Jamesexite说道:

    order cenforce: buy cenforce – Purchase Cenforce Online

  10. Elmersoalf说道:

    Generic Tadalafil 20mg price Generic Tadalafil 20mg price cialis for sale

  11. Charlesvox说道:

    https://cenforce.pro/# cenforce for sale

  12. Charlesvox说道:

    http://viagras.online/# Cheap generic Viagra

  13. Charlesvox说道:

    http://levitrav.store/# Levitra generic best price

  14. RandallGuesE说道:

    cheap propecia: cost generic propecia for sale – buying propecia pill

  15. Davidfrify说道:

    cytotec abortion pill cytotec online order cytotec online

  16. Davidfrify说道:

    cytotec abortion pill cytotec buy online usa buy cytotec online

  17. RonaldSwobe说道:

    https://lisinopril.network/# lisinopril 20mg daily

  18. RandallGuesE说道:

    tamoxifen and uterine thickening: tamoxifen and depression – tamoxifen and uterine thickening

  19. Davidfrify说道:

    cipro 500mg best prices ciprofloxacin generic buy cipro cheap

  20. RandallGuesE说道:

    tamoxifen warning: tamoxifen vs clomid – cost of tamoxifen

  21. WilliamRen说道:

    http://lisinopril.network/# lisinopril 5 mg buy

  22. WilliamRen说道:

    http://lisinopril.network/# zestoretic 10 12.5 mg

  23. WilliamRen说道:

    https://finasteride.store/# order propecia without dr prescription

  24. Davidfrify说道:

    purchase cytotec Cytotec 200mcg price Misoprostol 200 mg buy online

  25. Davidfrify说道:

    propecia price order generic propecia price propecia without insurance

  26. RandallGuesE说道:

    buy cipro online: cipro online no prescription in the usa – where can i buy cipro online

  27. RonaldSwobe说道:

    https://finasteride.store/# generic propecia without dr prescription

  28. RandallGuesE说道:

    buy ciprofloxacin over the counter: ciprofloxacin order online – where can i buy cipro online

  29. RonaldSwobe说道:

    http://ciprofloxacin.tech/# buy cipro cheap

  30. Davidfrify说道:

    Abortion pills online buy misoprostol over the counter buy misoprostol over the counter

  31. RandallGuesE说道:

    cipro generic: ciprofloxacin order online – where can i buy cipro online

  32. WilliamRen说道:

    http://nolvadex.life/# where can i buy nolvadex

  33. WilliamRen说道:

    http://finasteride.store/# buying cheap propecia without prescription

  34. WilliamRen说道:

    http://cytotec.club/# buy cytotec

  35. Davidfrify说道:

    lisinopril 5 mg price drug lisinopril 5 mg lisinopril 4214

  36. Davidfrify说道:

    buy generic ciprofloxacin cipro ciprofloxacin order online

  37. RandallGuesE说道:

    nolvadex online: tamoxifen 20 mg tablet – tamoxifen effectiveness

  38. Davidfrify说道:

    order cytotec online buy cytotec in usa buy cytotec

  39. RandallGuesE说道:

    buy cytotec online fast delivery: Misoprostol 200 mg buy online – buy cytotec online

  40. RonaldSwobe说道:

    http://lisinopril.network/# lisinopril 5 mg uk price

  41. WilliamRen说道:

    https://cytotec.club/# cytotec buy online usa

  42. RandallGuesE说道:

    tamoxifen menopause: should i take tamoxifen – arimidex vs tamoxifen bodybuilding

  43. Davidfrify说道:

    tamoxifen for breast cancer prevention tamoxifen and antidepressants natural alternatives to tamoxifen

  44. WilliamRen说道:

    http://finasteride.store/# cost cheap propecia online

  45. Davidfrify说道:

    buying propecia tablets buy propecia for sale cost of cheap propecia without rx

  46. Davidfrify说道:

    cheap propecia for sale cost cheap propecia without insurance propecia rx

  47. RandallGuesE说道:

    buy cytotec pills online cheap: buy cytotec over the counter – buy cytotec pills online cheap

  48. RandallGuesE说道:

    cytotec pills online: cytotec abortion pill – buy cytotec online fast delivery

  49. RonaldSwobe说道:

    https://lisinopril.network/# lisinopril tabs 88mg

回复 Davidfrify 取消回复

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