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

/ 6,371评论 / 25440阅读 / 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. h scaffolding说道:

    Some truly fantastic posts on this web site , appreciate it for contribution.

  2. That is a very good tip particularly to those new to the blogosphere. Brief but very accurate information… Many thanks for sharing this one. A must read article.

  3. every woman loves to wear those pretty but expensive diamond rings, i would love to give my girlfriend a diamond ring”

  4. I randomly browse blogs on the web, and that i discover your article to be very informational. I even have already bookmark it on my browser, so as that I can view your blog publish another time later. Additionally, i am wondering whether or not your weblog is open for link exchange, as i really wish to trade links with you. I do not normally do that, but I hope that we will have a mutual hyperlink exchange. Let me understand and have an ideal day!

  5. I’m impressed, I have to admit. Genuinely rarely will i encounter a blog that’s both educative and entertaining, and let me tell you, you might have hit the nail about the head. Your idea is outstanding; the problem is something that too few folks are speaking intelligently about. I am very happy i came across this around my look for something in regards to this.

  6. Way cool! Some extremely valid points! I appreciate you penning this write-up and the rest of the website is also really good.

  7. Michaeltrale说道:

    amoxicillin online no prescription: amoxil online – amoxicillin 500 mg online
    purchase amoxicillin online

  8. Robertver说道:

    https://azithromycinca.shop/# buy doxycycline 100mg uk
    doxycycline 100 mg forsale outside the us

  9. Michaeltrale说道:

    amoxicillin 500mg capsule cost: doxycyclineca – amoxicillin cephalexin
    prescription for amoxicillin

  10. Robertver说道:

    https://azithromycinca.shop/# doxycycline hydrochloride 100mg
    buy generic doxycycline 40mg

  11. Robertver说道:

    http://azithromycinca.com/# doxycycline online australia
    cheap doxycycline online

  12. Michaeltrale说道:

    where can i buy amoxocillin: cheapest amoxicillin – amoxicillin 500mg without prescription
    amoxicillin 500 mg without a prescription

  13. Michaeltrale说道:

    purchase amoxicillin 500 mg: doxycyclineca – order amoxicillin online
    canadian pharmacy amoxicillin

  14. Michaeltrale说道:

    buy amoxil: amoxil – amoxicillin 500 mg online
    amoxicillin 500mg prescription

  15. Robertver说道:

    https://azithromycinca.shop/# where can i purchase doxycycline
    doxycycline over the counter

  16. Robertver说道:

    https://azithromycinca.com/# doxycycline otc
    doxycycline 500mg

  17. Robertver说道:

    https://azithromycinca.shop/# order doxycycline online uk
    doxycycline 50 medicine

  18. seo说道:

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

    If you know of any please share. Appreciate it!
    I saw similar art here

  19. Clydewal说道:

    generic clomid online: clomid Prednisonerxa – where can i buy cheap clomid without rx

  20. Clydewal说道:

    prednisone 5093: Steroid – buy prednisone online no script

  21. Clydewal说道:

    prednisone 10mg buy online: Deltasone – prednisone 50

  22. Clydewal说道:

    can i get cheap clomid tablets: prednisonerxa.com – can i get generic clomid online

  23. Clydewal说道:

    can i buy prednisone over the counter in usa: prednisone – prednisone 20 mg

  24. Clydewal说道:

    zithromax online usa: cheapest Azithromycin – buy zithromax online with mastercard

  25. Clydewal说道:

    amoxicillin 500mg price canada: amoxil – antibiotic amoxicillin

  26. Billyziz说道:

    price for amoxicillin 875 mg amoxil best price amoxicillin 500 mg online

  27. Hello there! I could have sworn I’ve visited this website before but after browsing through a few of the posts I realized it’s new to me. Regardless, I’m definitely happy I found it and I’ll be bookmarking it and checking back regularly!

  28. Clydewal说道:

    buy doxycycline 100mg capsules: azithromycinca.shop – doxycycline buy online us

  29. Billyziz说道:

    how to get zithromax online zithromax zithromax drug

  30. Clydewal说道:

    get clomid online: best price – where can i buy clomid without prescription

  31. Billyziz说道:

    order prednisone with mastercard debit buy online prednisone online sale

  32. Carlosnatry说道:

    prednisone 3 tablets daily: Steroid – prednisone buy

  33. Clydewal说道:

    generic amoxicillin over the counter: amoxil online – how to buy amoxycillin

  34. Clydewal说道:

    buy prednisone no prescription: prednisone – prednisone 5443

  35. Billyziz说道:

    purchase zithromax online Azithromycin best price how to get zithromax

  36. Clydewal说道:

    order doxycycline no prescription: doxycycline azithromycinca – cheap doxycycline 100mg capsule

  37. Billyziz说道:

    zithromax generic cost Azithromycin best price zithromax without prescription

  38. Carlosnatry说道:

    zithromax capsules price: Azithromycin best price – buy zithromax 500mg online

  39. Clydewal说道:

    order prednisone 10 mg tablet: prednisone clomidca – over the counter prednisone pills

  40. Billyziz说道:

    buy amoxicillin online mexico buy cheapest antibiotics order amoxicillin 500mg

  41. Clydewal说道:

    antibiotic doxycycline: azithromycinca.shop – where to buy doxycycline online

  42. Charlescoofs说道:

    http://amoxicillinca.com/# zithromax 500mg

  43. Billyziz说道:

    amoxicillin 500 mg without a prescription cheapest amoxicillin amoxicillin 500 tablet

  44. I absolutely love your website.. Great colors & theme. Did you build this site yourself? Please reply back as I’m trying to create my own personal site and want to find out where you got this from or what the theme is called. Kudos.

  45. Billyziz说道:

    clomid tablet Prednisonerxa where buy clomid no prescription

  46. Carlosnatry说道:

    30mg prednisone: clomidca – can i buy prednisone online without prescription

  47. Charlescoofs说道:

    https://azithromycinca.com/# doxycycline capsules purchase

  48. Clydewal说道:

    where can you get amoxicillin: cheapest amoxicillin – buy amoxicillin online uk

  49. Billyziz说道:

    order doxycycline capsules online buy tetracycline antibiotics where to buy doxycycline online

发表回复

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