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

/ 2,558评论 / 10837阅读 / 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. RobertEsses说道:

    https://tadalafiliq.com/# Buy Cialis online

  2. Ralphnus说道:

    https://kamagraiq.shop/# Kamagra 100mg price

  3. Johnniecew说道:

    http://tadalafiliq.shop/# Cialis without a doctor prescription

  4. IsaacPem说道:

    cialis for sale: tadalafil iq – Generic Cialis price

  5. IsaacPem说道:

    Kamagra tablets: Kamagra 100mg – Kamagra 100mg price

  6. RobertEsses说道:

    http://kamagraiq.com/# cheap kamagra

  7. Chesterbloks说道:

    Sildenafil 100mg price: buy viagra online – Cheap Viagra 100mg

  8. IsaacPem说道:

    Kamagra 100mg price: Kamagra Iq – buy kamagra online usa

  9. RobertEsses说道:

    https://kamagraiq.com/# Kamagra 100mg price

  10. IsaacPem说道:

    cheapest cialis: cheapest cialis – Cheap Cialis

  11. Johnniecew说道:

    https://tadalafiliq.com/# Generic Cialis without a doctor prescription

  12. RobertEsses说道:

    https://kamagraiq.com/# sildenafil oral jelly 100mg kamagra

  13. IsaacPem说道:

    Viagra without a doctor prescription Canada: generic ed pills – Viagra generic over the counter

  14. Ralphnus说道:

    https://tadalafiliq.com/# Cialis 20mg price in USA

  15. IsaacPem说道:

    Generic Cialis price: cheapest cialis – Cialis over the counter

  16. Johnniecew说道:

    http://sildenafiliq.com/# sildenafil 50 mg price

  17. IsaacPem说道:

    Buy Cialis online: cialis generic – Cialis without a doctor prescription

  18. Chesterbloks说道:

    Generic Viagra online: sildenafil iq – buy Viagra online

  19. IsaacPem说道:

    Sildenafil Citrate Tablets 100mg: over the counter sildenafil – Cheap generic Viagra

  20. Hey there! Do you know if they make any plugins
    to help with Search Engine Optimization? I’m trying to get my website to rank for some
    targeted keywords but I’m not seeing very good success.
    If you know of any please share. Kudos! I saw similar text here: GSA Verified List

  21. IsaacPem说道:

    Order Viagra 50 mg online: buy viagra online – Buy generic 100mg Viagra online

  22. Johnniecew说道:

    https://kamagraiq.shop/# Kamagra 100mg

  23. Ralphnus说道:

    https://sildenafiliq.xyz/# sildenafil online

  24. IsaacPem说道:

    buy kamagra online usa: kamagra best price – Kamagra 100mg price

  25. IsaacPem说道:

    cialis generic: Cialis 20mg price in USA – Tadalafil price

  26. Chesterbloks说道:

    Buy Tadalafil 20mg: Cialis over the counter – cheapest cialis

  27. Johnniecew说道:

    http://sildenafiliq.com/# Viagra online price

  28. IsaacPem说道:

    Generic Cialis price: Generic Tadalafil 20mg price – Cheap Cialis

  29. Ralphnus说道:

    https://tadalafiliq.shop/# п»їcialis generic

  30. RobertFup说道:

    https://zithromaxall.com/# order zithromax over the counter

  31. Jamesscurl说道:

    http://zithromaxall.shop/# zithromax coupon

  32. DavidEvedo说道:

    amoxicillin discount: amoxicillin 500mg buy online uk – amoxicillin 500mg price

  33. RobertFup说道:

    http://clomidall.shop/# can i buy generic clomid no prescription

  34. Edwardsmors说道:

    buy amoxicillin canada: amoxicillin 500mg capsules – how to buy amoxycillin

  35. RobertFup说道:

    http://clomidall.shop/# where can i buy clomid prices

  36. RobertFup说道:

    http://zithromaxall.com/# zithromax tablets

  37. RobertFup说道:

    http://prednisoneall.shop/# prednisone tablets

  38. RobertFup说道:

    https://clomidall.com/# buying generic clomid tablets

  39. Jamesscurl说道:

    http://amoxilall.shop/# amoxicillin buy online canada

  40. DavidEvedo说道:

    prednisone 10 mg canada: 1 mg prednisone daily – buying prednisone from canada

  41. RobertFup说道:

    https://prednisoneall.shop/# prednisone 0.5 mg

  42. Edwardsmors说道:

    zithromax cost uk: zithromax cost uk – where can i buy zithromax capsules

  43. RobertFup说道:

    http://prednisoneall.com/# generic prednisone cost

  44. RobertFup说道:

    http://prednisoneall.com/# buy generic prednisone online

  45. Jamesscurl说道:

    https://amoxilall.com/# 875 mg amoxicillin cost

  46. Scrapebox List说道:

    Hi there! Do you know if they make any plugins to assist with Search Engine Optimization? I’m trying to get my blog to
    rank for some targeted keywords but I’m not seeing very good gains.

    If you know of any please share. Appreciate it!
    You can read similar text here: Scrapebox AA List

  47. RobertFup说道:

    https://clomidall.shop/# cost of generic clomid no prescription

  48. RobertFup说道:

    https://prednisoneall.shop/# prednisone for cheap

  49. RobertFup说道:

    https://amoxilall.shop/# where can i get amoxicillin 500 mg

  50. DavidEvedo说道:

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

发表回复

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