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

/ 6,369评论 / 25426阅读 / 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. Oh my goodness! an excellent article dude. Thanks a ton However My business is experiencing problem with ur rss . Do not know why Struggle to join it. Will there be everyone finding identical rss issue? Anyone who knows kindly respond. Thnkx

  2. There is noticeably a lot of money to know about this. I assume you made particular nice points in features also.

  3. This is a proper blog for everyone who hopes to learn about this topic. You are aware of much its almost tricky to argue on hand (not that I really would want…HaHa). You actually put a brand new spin on a topic thats been discussed for some time. Great stuff, just excellent!

  4. you can get some free catalogs over the internet easily if you just search on google’

  5. Hey there! I just wanted to ask if you ever have any problems with hackers? My last blog (wordpress) was hacked and I ended up losing a few months of hard work due to no back up. Do you have any solutions to prevent hackers?

  6. Thanks for the feature again! I guess it means I am doing a lot of things right.

  7. Howdy, i read your blog occasionally and i own a similar one and i was just curious if you get a lot of spam feedback? If so how do you reduce it, any plugin or anything you can advise? I get so much lately it’s driving me mad so any support is very much appreciated.

  8. Writing a great article takes commitment and pride in one’s work. It’s apparent that this writer has it together. Each point is well formatted. The grammar and spelling is excellent.

  9. Can I simply say what a reduction to search out someone who actually is aware of what theyre speaking about on the internet. You definitely know easy methods to bring an issue to gentle and make it important. More folks must read this and understand this facet of the story. I cant believe youre not more widespread because you undoubtedly have the gift.

  10. This website online can be a stroll-by means of for all the data you needed about this and didn’t know who to ask. Glimpse here, and you’ll undoubtedly uncover it.

  11. IgnacioGinia说道:

    pharmacie en ligne livraison europe: pharmacie en ligne fiable – п»їpharmacie en ligne france

  12. AllenTal说道:

    Viagra pas cher livraison rapide france: Viagra generique en pharmacie – Viagra pas cher livraison rapide france

  13. Robertrib说道:

    Pharmacie sans ordonnance: acheter mГ©dicament en ligne sans ordonnance – pharmacie en ligne france livraison belgique

  14. Robertrib说道:

    pharmacie en ligne france fiable: cialis sans ordonnance – Pharmacie Internationale en ligne

  15. AllenTal说道:

    Viagra vente libre allemagne: Acheter du Viagra sans ordonnance – Viagra homme prix en pharmacie sans ordonnance

  16. Robertrib说道:

    vente de mГ©dicament en ligne: pharmacie en ligne pas cher – pharmacie en ligne

  17. AllenTal说道:

    trouver un mГ©dicament en pharmacie: levitra generique sites surs – pharmacie en ligne pas cher

  18. IgnacioGinia说道:

    pharmacie en ligne avec ordonnance: kamagra 100mg prix – pharmacie en ligne pas cher

  19. Robertrib说道:

    pharmacie en ligne france livraison belgique: Cialis sans ordonnance 24h – pharmacie en ligne

  20. AllenTal说道:

    Viagra pas cher livraison rapide france: Viagra sans ordonnance 24h – Viagra sans ordonnance 24h Amazon

  21. Juliusfum说道:

    pharmacie en ligne livraison europe: cialis sans ordonnance – pharmacie en ligne

  22. Robertrib说道:

    pharmacie en ligne sans ordonnance: achat kamagra – pharmacies en ligne certifiГ©es

  23. Juliusfum说道:

    pharmacies en ligne certifiГ©es: levitra generique – trouver un mГ©dicament en pharmacie

  24. AllenTal说道:

    Viagra sans ordonnance 24h suisse: Viagra generique en pharmacie – Viagra gГ©nГ©rique sans ordonnance en pharmacie

  25. Robertrib说道:

    vente de mГ©dicament en ligne: Levitra 20mg prix en pharmacie – pharmacie en ligne fiable

  26. AllenTal说道:

    pharmacie en ligne avec ordonnance: kamagra pas cher – Pharmacie en ligne livraison Europe

  27. Robertrib说道:

    Achat mГ©dicament en ligne fiable: levitra en ligne – pharmacie en ligne sans ordonnance

  28. IgnacioGinia说道:

    pharmacie en ligne fiable: levitra en ligne – vente de mГ©dicament en ligne

  29. AllenTal说道:

    Achat mГ©dicament en ligne fiable: kamagra pas cher – pharmacie en ligne france pas cher

  30. AllenTal说道:

    Pharmacie Internationale en ligne: kamagra gel – acheter mГ©dicament en ligne sans ordonnance

  31. AllenTal说道:

    pharmacie en ligne france pas cher: Acheter Cialis 20 mg pas cher – pharmacie en ligne france pas cher

  32. click说道:

    You consistently produce high-quality content that is both informative and enjoyable to read. This post was no exception. Keep it up!pulsepeak

  33. AllenTal说道:

    Viagra vente libre allemagne: Viagra generique en pharmacie – Viagra gГ©nГ©rique sans ordonnance en pharmacie

  34. IgnacioGinia说道:

    pharmacie en ligne fiable: Medicaments en ligne livres en 24h – pharmacie en ligne france livraison belgique

  35. AllenTal说道:

    Viagra gГ©nГ©rique sans ordonnance en pharmacie: Viagra pas cher livraison rapide france – Prix du Viagra en pharmacie en France

  36. AllenTal说道:

    vente de mГ©dicament en ligne: pharmacie en ligne pas cher – pharmacie en ligne france fiable

  37. RobertDer说道:

    https://viaenligne.com/# Viagra générique sans ordonnance en pharmacie

  38. AllenTal说道:

    Viagra sans ordonnance 24h suisse: viagra en ligne – SildГ©nafil Teva 100 mg acheter

  39. AllenTal说道:

    pharmacie en ligne france livraison internationale: cialis prix – acheter mГ©dicament en ligne sans ordonnance

  40. AllenTal说道:

    pharmacie en ligne france livraison belgique: cialis prix – Pharmacie Internationale en ligne

  41. AllenTal说道:

    Viagra 100 mg sans ordonnance: viagra en ligne – SildГ©nafil 100mg pharmacie en ligne

  42. AllenTal说道:

    pharmacie en ligne france livraison belgique: kamagra 100mg prix – pharmacie en ligne france pas cher

  43. AllenTal说道:

    pharmacie en ligne: Levitra pharmacie en ligne – pharmacie en ligne france pas cher

  44. RobertDer说道:

    https://viaenligne.com/# Meilleur Viagra sans ordonnance 24h

  45. IgnacioGinia说道:

    Quand une femme prend du Viagra homme: Viagra generique en pharmacie – Viagra femme sans ordonnance 24h

  46. Georgesuima说道:

    pharmacies en ligne certifiГ©es: Levitra pharmacie en ligne – pharmacie en ligne france livraison internationale

  47. AllenTal说道:

    Viagra pas cher livraison rapide france: Viagra sans ordonnance 24h – Viagra pas cher livraison rapide france

  48. Georgesuima说道:

    pharmacie en ligne france livraison belgique: pharmacie en ligne pas cher – pharmacie en ligne sans ordonnance

  49. AllenTal说道:

    pharmacie en ligne pas cher: achat kamagra – Pharmacie en ligne livraison Europe

  50. AllenTal说道:

    Achat mГ©dicament en ligne fiable: kamagra oral jelly – acheter mГ©dicament en ligne sans ordonnance

发表回复

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