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

/ 6,359评论 / 25388阅读 / 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. Marvinmef说道:

    buy misoprostol over the counter cytotec online buy cytotec over the counter

  2. Robertguelm说道:

    neurontin 300 mg cap: neurontin drug – neurontin tablets 300mg

  3. RobertPet说道:

    http://lisinopril.club/# prinivil 2.5 mg

  4. Marvinmef说道:

    buying generic propecia pill buying generic propecia without prescription propecia generic

  5. ThomasTam说道:

    order propecia without insurance: buy cheap propecia – order cheap propecia without a prescription

  6. ThomasTam说道:

    cost of lisinopril: lisinopril pills for sale – lisinopril online canada

  7. Marvinmef说道:

    buy neurontin online uk can i buy neurontin over the counter gabapentin generic

  8. ThomasTam说道:

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

  9. Marvinmef说道:

    buying propecia without a prescription propecia rx cost cheap propecia prices

  10. Marvinmef说道:

    can you buy generic clomid pills buy generic clomid can i get generic clomid pill

  11. Robertguelm说道:

    canada neurontin 100mg discount: buy neurontin canada – neurontin coupon

  12. RobertPet说道:

    http://cytotec.xyz/# buy cytotec online

  13. ThomasTam说道:

    where buy cheap clomid without dr prescription: can you get clomid price – buy cheap clomid price

  14. ThomasTam说道:

    buying cheap propecia without insurance: get generic propecia without insurance – buy cheap propecia prices

  15. Marvinmef说道:

    208 lisinopril buy lisinopril online on line order lisinopril 20mg

  16. ThomasTam说道:

    propecia without rx: cost of propecia online – buy propecia now

  17. RobertPet说道:

    https://clomiphene.shop/# where to get clomid pills

  18. Robertguelm说道:

    cheap propecia without prescription: cost propecia no prescription – cheap propecia tablets

  19. Marvinmef说道:

    cytotec buy online usa cytotec buy online usa purchase cytotec

  20. Marvinmef说道:

    generic lisinopril 10 mg lisinopril 20 mg over the counter zestoretic 10 12.5 mg

  21. ThomasTam说道:

    generic propecia without insurance: cost cheap propecia price – order cheap propecia pills

  22. Marvinmef说道:

    neurontin prescription medication canada where to buy neurontin neurontin 300 mg buy

  23. ThomasTam说道:

    where can i buy neurontin online: drug neurontin 20 mg – neurontin brand name in india

  24. ThomasTam说道:

    zestril 40: zestoretic 20 – lisinopril 30 mg daily

  25. RobertPet说道:

    https://cytotec.xyz/# cytotec online

  26. JamesPouff说道:

    https://gabapentin.club/# buy neurontin online

  27. JamesPouff说道:

    http://cytotec.xyz/# buy cytotec pills online cheap

  28. Marvinmef说道:

    buy cheap lisinopril 40mg buy lisinopril 5 mg generic lisinopril 10 mg

  29. JamesPouff说道:

    https://clomiphene.shop/# can i get generic clomid without dr prescription

  30. Marvinmef说道:

    cost generic clomid without insurance how to get cheap clomid without rx where buy generic clomid without a prescription

  31. ThomasTam说道:

    neurontin generic brand: neurontin gabapentin – neurontin 600 mg coupon

  32. Marvinmef说道:

    cost generic propecia price order cheap propecia tablets order propecia without prescription

  33. ThomasTam说道:

    neurontin without prescription: neurontin 300 mg pill – gabapentin online

  34. ThomasTam说道:

    how can i get generic clomid online: can i purchase clomid now – generic clomid prices

  35. JamesPouff说道:

    https://clomiphene.shop/# can i buy cheap clomid for sale

  36. Robertguelm说道:

    lisinopril 25: zestril 40 mg – lisinopril tablet 40 mg

  37. Marvinmef说道:

    buying generic propecia order generic propecia without insurance propecia generics

  38. RobertPet说道:

    http://clomiphene.shop/# can you get clomid without a prescription

  39. Marvinmef说道:

    lisinopril 40mg lisinopril 102 zestoretic generic

  40. JamesPouff说道:

    http://clomiphene.shop/# can you buy cheap clomid without insurance

  41. RobertPet说道:

    https://lisinopril.club/# zestril 20 mg price canadian pharmacy

  42. Marvinmef说道:

    lisinopril 5 mg tablet price zestril 5mg price in india lisinopril 5 mg tabs

  43. ThomasTam说道:

    lisinopril 20mg for sale: can i buy generic lisinopril online – lisinopril 40mg prescription cost

  44. ThomasTam说道:

    neurontin buy from canada: neurontin 400 mg price – buy cheap neurontin online

  45. ThomasTam说道:

    buy cytotec: buy cytotec online – buy cytotec pills online cheap

  46. JamesPouff说道:

    http://gabapentin.club/# buy neurontin 100 mg

  47. JamesPouff说道:

    https://gabapentin.club/# neurontin 600 mg pill

  48. Marvinmef说道:

    neurontin 300 mg caps neurontin brand name 800mg gabapentin 600 mg

  49. Robertguelm说道:

    can i order cheap clomid: can you get clomid online – clomid for sale

发表回复

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