vue2.0+SVG實現(xiàn)音樂播放圓形進(jìn)度條組件
vue2.0+SVG實現(xiàn)音樂播放圓形進(jìn)度條組件,傳入實時百分比實現(xiàn)圓圈進(jìn)度動畫效果

需求分析:
類似于大多數(shù)音樂播放器中等mini播放器控制按鈕,顯示播放進(jìn)度,實時更新進(jìn)度。
progress-circle.vue源碼:
<template>
<div class="progress-circle">
<svg :width="radius" :height="radius" viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle class="progress-background" r="50" cx="50" cy="50" fill="transparent"/>
<circle class="progress-bar" r="50" cx="50" cy="50" fill="transparent" :stroke-dasharray="dashArray"
:stroke-dashoffset="dashOffset"/>
</svg>
<slot></slot>
</div>
</template>
<script type="text/ecmascript-6">
export default {
props: {
radius: {
type: String,
default: '0.32rem'
},
percent: {
type: Number,
default: 0
}
},
data() {
return {
dashArray: Math.PI * 100
}
},
computed: {
dashOffset() {
return (1 - this.percent) * this.dashArray
}
}
}
</script>
<style scoped lang="stylus" rel="stylesheet/stylus">
.progress-circle
position: relative
circle
stroke-width: 0.16rem
transform-origin: center
&.progress-background
transform: scale(0.9)
stroke: rgba(255, 205, 49, 0.5)
&.progress-bar
transform: scale(0.9) rotate(-90deg)
stroke: #ffcd32
</style>
本組件沒有使用本地資源,可直接只用,在父組件中導(dǎo)入并注冊后,調(diào)用組件。
父組件DOM結(jié)構(gòu):
<div class="control"> <progress-circle :radius="radius" :percent="percent"> <i @click.stop="togglePlaying" class="icon-mini" :class="iconMiniPlay"></i> </progress-circle> </div>
解釋:其中<i></i>中引用的是制作的css圖標(biāo)(播放/暫停按鈕),通過iconMiniPlay決定展現(xiàn)是播放按鈕還是暫停按鈕(本例子只介紹原型進(jìn)圖條組件的開發(fā)和使用,因此不多介紹),設(shè)置圖標(biāo)的大小務(wù)必注意與radius一致,不明白為什么的話建議嘗試一下,實踐出真知噢。
需要像組件傳入的參數(shù):
svg圈圈大小radius以及歌曲播放進(jìn)度百分比percent,兩個數(shù)據(jù)來源:

解釋:
percent通過audio標(biāo)簽的currentTime獲取,duration為接口獲取的當(dāng)前歌曲總長度,相除則為當(dāng)前進(jìn)度百分比。
radius可根據(jù)自身開發(fā)時所需規(guī)格設(shè)置(其他布局、樣式之類的也是)
父組件樣式(本人使用stylus):
.control position absolute top 0.35rem right 1rem color $color-theme-d .icon-mini font-size: 0.64rem position: absolute left: 0 top: 0
最近可以變聽歌邊開發(fā)了。
開發(fā)完并運(yùn)用此組件,設(shè)置適當(dāng)?shù)牟季?、樣式后的效果?br />

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue 使用beforeEach實現(xiàn)登錄狀態(tài)檢查功能
今天小編就為大家分享一篇Vue 使用beforeEach實現(xiàn)登錄狀態(tài)檢查功能,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10
vue項目實現(xiàn)點擊目標(biāo)區(qū)域之外可關(guān)閉(隱藏)目標(biāo)區(qū)域
這篇文章主要介紹了vue項目實現(xiàn)點擊目標(biāo)區(qū)域之外可關(guān)閉(隱藏)目標(biāo)區(qū)域,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03
vue項目使用typescript創(chuàng)建抽象類及其使用方式
這篇文章主要介紹了vue項目使用typescript創(chuàng)建抽象類及其使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03
elementui源碼學(xué)習(xí)仿寫el-collapse示例
這篇文章主要為大家介紹了elementui源碼學(xué)習(xí)之仿寫el-collapse示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12

