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

/ 6,356评论 / 25378阅读 / 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说道:

    rx lisinopril lisinopril 2.5 mg tablet can you buy lisinopril online

  2. JamesPouff说道:

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

  3. RobertPet说道:

    https://gabapentin.club/# neurontin 1000 mg

  4. Marvinmef说道:

    propecia no prescription cost of generic propecia without a prescription cost of generic propecia without prescription

  5. ThomasTam说道:

    cost cheap propecia without prescription: cheap propecia without rx – generic propecia online

  6. Robertguelm说道:

    buy zestril online: lisinopril 102 – prescription medicine lisinopril

  7. ThomasTam说道:

    cost generic clomid: cheap clomid now – can i get generic clomid without rx

  8. ThomasTam说道:

    neurontin for sale online: can i buy neurontin over the counter – neurontin generic

  9. JamesPouff说道:

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

  10. Marvinmef说道:

    buy zestoretic online lisinopril 5 mg brand name where can i purchase lisinopril

  11. JamesPouff说道:

    https://cytotec.xyz/# cytotec pills buy online

  12. JamesPouff说道:

    https://propeciaf.online/# cost generic propecia without insurance

  13. Marvinmef说道:

    buy cytotec pills purchase cytotec buy cytotec pills

  14. ThomasTam说道:

    neurontin capsules 100mg: neurontin uk – neurontin 100mg capsule price

  15. RobertPet说道:

    http://gabapentin.club/# neurontin 800mg

  16. Marvinmef说道:

    order propecia get cheap propecia tablets get generic propecia pills

  17. ThomasTam说道:

    can you get clomid without a prescription: where can i buy clomid for sale – how can i get cheap clomid without prescription

  18. ThomasTam说道:

    buy cytotec pills: п»їcytotec pills online – Misoprostol 200 mg buy online

  19. RobertPet说道:

    https://propeciaf.online/# order propecia tablets

  20. Marvinmef说道:

    buy cytotec pills online cheap buy cytotec Misoprostol 200 mg buy online

  21. Marvinmef说道:

    neurontin 600 mg capsule neurontin 202 neurontin price india

  22. Marvinmef说道:

    cost of clomid without insurance get clomid tablets can i order generic clomid tablets

  23. ThomasTam说道:

    buy cytotec over the counter: buy cytotec – cytotec abortion pill

  24. ThomasTam说道:

    Cytotec 200mcg price: buy misoprostol over the counter – buy cytotec online

  25. Robertguelm说道:

    get cheap clomid price: buy clomid pills – can i purchase generic clomid prices

  26. ThomasTam说道:

    cost of generic propecia: cost of propecia without dr prescription – buy propecia without prescription

  27. RobertPet说道:

    http://cytotec.xyz/# Abortion pills online

  28. JamesPouff说道:

    http://gabapentin.club/# prescription medication neurontin

  29. Marvinmef说道:

    can i order cheap clomid prices can you buy cheap clomid now buying clomid without rx

  30. Marvinmef说道:

    cheap propecia price propecia for sale cost propecia without prescription

  31. JamesPouff说道:

    https://gabapentin.club/# neurontin 500 mg

  32. Marvinmef说道:

    get generic propecia pill buying propecia without rx cost of propecia no prescription

  33. ThomasTam说道:

    can you buy neurontin over the counter: neurontin pills for sale – purchase neurontin canada

  34. JamesPouff说道:

    https://gabapentin.club/# neurontin 50mg cost

  35. ThomasTam说道:

    cost of brand name lisinopril: lisinopril 20 mg pill – lisinopril 40mg

  36. Robertguelm说道:

    neurontin over the counter: neurontin india – medicine neurontin 300 mg

  37. ThomasTam说道:

    cytotec abortion pill: buy cytotec pills online cheap – buy cytotec over the counter

  38. RobertPet说道:

    http://propeciaf.online/# order generic propecia for sale

  39. Robertswela说道:

    mexico pharmacies prescription drugs: mexican online pharmacies prescription drugs – mexican online pharmacies prescription drugs

  40. KennethFobby说道:

    http://mexicanpharmacy1st.com/# mexican rx online

  41. Manuelloupe说道:

    mexico pharmacy mexico drug stores pharmacies mexican rx online

  42. Albertnab说道:

    pharmacies in mexico that ship to usa: best online pharmacies in mexico – mexican online pharmacies prescription drugs

  43. Thomasliest说道:

    buying from online mexican pharmacy: mexico drug stores pharmacies – pharmacies in mexico that ship to usa

  44. Robertswela说道:

    mexican border pharmacies shipping to usa: mexican mail order pharmacies – buying prescription drugs in mexico

  45. Albertnab说道:

    mexican rx online: medicine in mexico pharmacies – mexico pharmacies prescription drugs

  46. Robertswela说道:

    mexican pharmaceuticals online: pharmacies in mexico that ship to usa – mexican pharmaceuticals online

  47. Manuelloupe说道:

    mexican online pharmacies prescription drugs mexican rx online mexican pharmaceuticals online

  48. Williamlyday说道:

    https://mexicanpharmacy1st.com/# mexico pharmacies prescription drugs

  49. Manuelloupe说道:

    mexico drug stores pharmacies mexico drug stores pharmacies mexican pharmaceuticals online

发表回复

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