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

/ 5,991评论 / 24314阅读 / 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. Whitescreen57说道:

    Oh my goodness! Incredible article dude! Many thanks, However I am having troubles with your RSS. I don’t understand the reason why I can’t subscribe to it. Is there anybody getting similar RSS issues? Anybody who knows the solution can you kindly respond? Thanx!

  2. RandyBulty说道:

    Farmacia online miglior prezzo: Farmacie online sicure – top farmacia online

  3. RandyBulty说道:

    Farmacia online piГ№ conveniente: farmacia online migliore – п»їFarmacia online migliore

  4. Tomasdrads说道:

    farmacia online piГ№ conveniente: Tadalafil generico migliore – Farmacie online sicure

  5. RandyBulty说道:

    п»їFarmacia online migliore: Avanafil prezzo – Farmacie online sicure

  6. Timothyomide说道:

    http://kamagrait.pro/# acquistare farmaci senza ricetta

  7. Tomasdrads说道:

    top farmacia online: Cialis generico 20 mg 8 compresse prezzo – farmacia online

  8. RandyBulty说道:

    farmacie online autorizzate elenco: kamagra gel prezzo – farmacie online affidabili

  9. Tomasdrads说道:

    п»їFarmacia online migliore: Farmacia online migliore – farmacie online sicure

  10. Tomasdrads说道:

    Farmacia online piГ№ conveniente: Farmacie on line spedizione gratuita – comprare farmaci online all’estero

  11. RandyBulty说道:

    migliori farmacie online 2024: kamagra oral jelly – farmacia online senza ricetta

  12. RandyBulty说道:

    farmacie online autorizzate elenco: Farmacia online piu conveniente – п»їFarmacia online migliore

  13. seperti ini说道:

    This page truly has all of the info I wanted about this subject and didn’t know who to ask.

  14. Timothyomide说道:

    https://kamagrait.pro/# farmaci senza ricetta elenco

  15. Tomasdrads说道:

    farmacia online: Farmacia online piu conveniente – top farmacia online

  16. RandyBulty说道:

    Farmacie online sicure: kamagra – farmacia online

  17. Timothyomide说道:

    https://kamagrait.pro/# comprare farmaci online all’estero

  18. 카지노톡说道:

    Hi, There’s no doubt that your site may be having internet browser compatibility issues. Whenever I take a look at your blog in Safari, it looks fine however when opening in Internet Explorer, it has some overlapping issues. I merely wanted to provide you with a quick heads up! Besides that, fantastic website.

  19. Good post. I learn something totally new and challenging on sites I stumbleupon every day. It will always be helpful to read through articles from other writers and practice something from their web sites.

  20. RandyBulty说道:

    farmacie online autorizzate elenco: kamagra oral jelly consegna 24 ore – acquistare farmaci senza ricetta

  21. Timothyomide说道:

    https://avanafil.pro/# acquistare farmaci senza ricetta

  22. Tomasdrads说道:

    Farmacie online sicure: kamagra gel – Farmacie online sicure

  23. Tomasdrads说道:

    Farmacia online miglior prezzo: kamagra – farmacia online senza ricetta

  24. RandyBulty说道:

    farmacie online autorizzate elenco: Farmacie online sicure – farmacie online sicure

  25. RandyBulty说道:

    farmaci senza ricetta elenco: Farmacie online sicure – comprare farmaci online con ricetta

  26. Matthewnouts说道:

    buy cytotec online: п»їcytotec pills online – buy misoprostol over the counter

  27. Matthewnouts说道:

    buy propecia online: buying generic propecia – buy cheap propecia tablets

  28. Matthewnouts说道:

    zithromax 250mg: zithromax cost australia – zithromax buy online no prescription

  29. Matthewnouts说道:

    how to lose weight on tamoxifen: tamoxifen buy – nolvadex during cycle

  30. LewisToite说道:

    http://propeciabestprice.pro/# cost of cheap propecia without a prescription

  31. Matthewnouts说道:

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

  32. LewisToite说道:

    http://prednisonebestprice.pro/# generic prednisone pills

  33. LewisToite说道:

    http://prednisonebestprice.pro/# prednisone purchase online

  34. tubidy说道:

    Great web site you’ve got here.. It’s hard to find good quality writing like yours nowadays. I seriously appreciate individuals like you! Take care!!

  35. Matthewnouts说道:

    does tamoxifen cause joint pain: nolvadex 10mg – nolvadex only pct

  36. Matthewnouts说道:

    buy prednisone online canada: can you buy prednisone over the counter in usa – can you buy prednisone online uk

  37. Matthewnouts说道:

    zithromax 500 price: zithromax generic cost – zithromax prescription in canada

  38. LewisToite说道:

    http://propeciabestprice.pro/# propecia without insurance

  39. Matthewnouts说道:

    prednisone no rx: prednisone 20 mg without prescription – prednisone 40 mg price

  40. newborn turbans说道:

    Aw, this was an exceptionally nice post. Spending some time and actual effort to generate a really good article… but what can I say… I hesitate a lot and never manage to get nearly anything done.

  41. Spot on with this write-up, I really believe this amazing site needs far more attention. I’ll probably be back again to see more, thanks for the advice.

  42. Matthewnouts说道:

    how much is zithromax 250 mg: how to get zithromax – can you buy zithromax over the counter

  43. Matthewnouts说道:

    cost of propecia no prescription: buy propecia prices – buy propecia price

  44. Matthewnouts说道:

    nolvadex 10mg: tamoxifen hair loss – does tamoxifen cause menopause

  45. LewisToite说道:

    http://cytotecbestprice.pro/# Abortion pills online

  46. LewisToite说道:

    http://nolvadexbestprice.pro/# where to buy nolvadex

发表回复

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