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

/ 7,383评论 / 28364阅读 / 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. ArmandoLiaig说道:

    lisinopril 15 mg tablets: lisinopril 20 mg canada – buy lisinopril

  2. Предлагаем услуги профессиональных инженеров офицальной мастерской.
    Еслли вы искали ремонт телевизоров samsung адреса, можете посмотреть на сайте: ремонт телевизоров samsung
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  3. Предлагаем услуги профессиональных инженеров офицальной мастерской.
    Еслли вы искали ремонт телевизоров samsung сервис, можете посмотреть на сайте: ремонт телевизоров samsung
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  4. iwin说道:

    Introducing to you the most prestigious online entertainment address today. Visit now to experience now!

  5. JaimeNer说道:

    can i order generic clomid tablets can i buy generic clomid where to buy clomid prices

  6. You’re so interesting! I don’t think I’ve read through anything like this before. So nice to find somebody with unique thoughts on this topic. Seriously.. thank you for starting this up. This web site is something that is needed on the internet, someone with a bit of originality.

  7. JimmieInawl说道:

    https://azithromycinus.com/# zithromax for sale usa

  8. ArmandoLiaig说道:

    10mg generic 10mg lisinopril: lisinopril 5 mg tabs – lisinopril 12.5 mg price

  9. RobertUnsuh说道:

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

  10. RobertUnsuh说道:

    buy cipro: ciprofloxacin generic – buy cipro without rx

  11. Introducing to you the most prestigious online entertainment address today. Visit now to experience now!

  12. JaimeNer说道:

    cost generic clomid pills buying clomid prices where to buy clomid without prescription

  13. ArmandoLiaig说道:

    prinivil 5mg tablet: lisinopril 25 mg cost – lisinopril 419

  14. JimmieInawl说道:

    https://ciprofloxacin.cheap/# buy cipro online canada

  15. sexmex porn说道:

    Greetings! Very useful advice within this article! It is the little changes that produce the biggest changes. Thanks a lot for sharing!

  16. ArmandoLiaig说道:

    ciprofloxacin generic: cipro 500mg best prices – buy cipro online canada

  17. RobertUnsuh说道:

    how to buy lisinopril: zestoretic 20 25 mg – lisinopril 20 mg price online

  18. RobertUnsuh说道:

    zestril over the counter: 25 mg lisinopril – lisinopril 10 best price

  19. JimmieInawl说道:

    https://clomid.store/# clomid sale

  20. JaimeNer说道:

    zithromax 1000 mg online zithromax over the counter buy zithromax without presc

  21. GO 88说道:

    Introducing to you the most prestigious online entertainment address today. Visit now to experience now!

  22. Loved the insight in this post. It’s very comprehensive and packed with helpful information. Fantastic effort!

  23. You ought to take part in a contest for one of the greatest blogs on the web. I am going to recommend this blog!

  24. ArmandoLiaig说道:

    prescription drug prices lisinopril: lisinopril 40 mg daily – where can i purchase lisinopril

  25. JaimeNer说道:

    cytotec pills buy online buy cytotec over the counter cytotec pills buy online

  26. ArmandoLiaig说道:

    Abortion pills online: п»їcytotec pills online – buy cytotec online

  27. JimmieInawl说道:

    https://ciprofloxacin.cheap/# cipro online no prescription in the usa

  28. Nice post. I learn something new and challenging on sites I stumbleupon every day. It’s always interesting to read articles from other authors and practice something from their websites.

  29. RobertUnsuh说道:

    buy cytotec in usa: buy cytotec pills – cytotec abortion pill

  30. JimmieInawl说道:

    https://lisinoprilus.com/# lisinopril with out prescription

  31. RobertUnsuh说道:

    buy lisinopril without a prescription: order lisinopril online united states – lisinopril pill 40 mg

发表回复

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