vue圓環(huán)百分比進(jìn)度條組件功能的實(shí)現(xiàn)
有需要的人可以參考一下,如果試用過,發(fā)現(xiàn)問題,歡迎留言告知,不勝感激。
功能介紹:
1、若頁面無刷新,且第一次傳值小于第二次傳值或者圓環(huán)初始化時執(zhí)行的是遞增動畫
2、若頁面無刷新,且第一次傳值大于第二次傳值則為執(zhí)行遞減動畫
3、中間展示的百分比數(shù)字有緩動動畫(速度同圓環(huán)進(jìn)度動畫一直)
4、動畫完成時會觸發(fā)動畫完成回調(diào)
5、外部傳值為圓環(huán)進(jìn)度百分比(整數(shù)),圓環(huán)動畫速度(整數(shù))
效果如圖所示:
<template> <div class="percentloop"> <div class="circle-left"> <div ref="leftcontent"></div> </div> <div class="circle-right"> <div ref="rightcontent"></div> </div> <div class="number"> {{ percent }} % </div> </div> </template> <script> export default { props: { percentNum: { type: [String, Number], default: 0 }, speed: { // 建議取值為0-3 type: [String, Number], default: 1 } }, data () { return { percent: 0, initDeg: 0, timeId: null, animationing: false } }, methods: { transformToDeg (percent) { let deg = 0 if (percent >= 100) { deg = 360 } else { deg = parseInt(360 * percent / 100) } return deg }, transformToPercent (deg) { let percent = 0 if (deg >= 360) { percent = 100 } else { percent = parseInt(100 * deg / 360) } return percent }, rotateLeft (deg) { // 大于180時,執(zhí)行的動畫 this.$refs.leftcontent.style.transform = 'rotate(' + (deg - 180) + 'deg)' }, rotateRight (deg) { // 小于180時,執(zhí)行的動畫 this.$refs.rightcontent.style.transform = 'rotate(' + deg + 'deg)' }, goRotate (deg) { this.animationing = true this.timeId = setInterval(() => { if (deg > this.initDeg) { // 遞增動畫 this.initDeg += Number(this.speed) if (this.initDeg >= 180) { this.rotateLeft(this.initDeg) this.rotateRight(180) // 為避免前后兩次傳入的百分比轉(zhuǎn)換為度數(shù)后的值不為步距的整數(shù),可能出現(xiàn)的左右轉(zhuǎn)動不到位的情況。 } else { this.rotateRight(this.initDeg) } } else { // 遞減動畫 this.initDeg -= Number(this.speed) if (this.initDeg >= 180) { this.rotateLeft(this.initDeg) } else { this.rotateLeft(180) // 為避免前后兩次傳入的百分比轉(zhuǎn)換為度數(shù)后的值不為步距的整數(shù),可能出現(xiàn)的左右轉(zhuǎn)動不到位的情況。 this.rotateRight(this.initDeg) } } this.percent = this.transformToPercent(this.initDeg) // 百分比數(shù)據(jù)滾動動畫 const remainer = Number(deg) - this.initDeg if (Math.abs(remainer) < this.speed) { this.initDeg += remainer if (this.initDeg > 180) { this.rotateLeft(deg) } else { this.rotateRight(deg) } this.animationFinished() } }, 10) }, animationFinished () { this.percent = this.percentNum // 百分比數(shù)據(jù)滾動動畫 this.animationing = false clearInterval(this.timeId) this.$emit('animationFinished') // 動畫完成的回調(diào) } }, created () { this.goRotate(this.transformToDeg(this.percentNum)) }, watch: { 'percentNum': function (val) { if (this.animationing) return this.goRotate(this.transformToDeg(val)) } } } </script> <style scoped lang="scss"> .percentloop { position: relative; width: 100%; height: 100%; border-radius: 50%; overflow: hidden; .circle-left, .circle-right { position: absolute; top: 0; left: 0; width: 50%; height: 100%; background-color: red; overflow: hidden; &>div { width: 100%; height: 100%; background-color: #8a8a8a; transform-origin: right center; /*transition: all .5s linear;*/ } } .circle-right { left: 50%; &>div { transform-origin: left center; } } .number { position: absolute; top: 9%; bottom: 9%; left: 9%; right: 9%; background-color: #fff; border-radius: 50%; overflow: hidden; display: flex; align-items: center; justify-content: center; color: #000; } } </style>
以上就是vue圓環(huán)百分比進(jìn)度條組件功能的實(shí)現(xiàn)的詳細(xì)內(nèi)容,更多關(guān)于vue進(jìn)度條的資料請關(guān)注腳本之家其它相關(guān)文章!
- Vue實(shí)現(xiàn)動態(tài)圓環(huán)百分比進(jìn)度條
- Springboot項(xiàng)目中運(yùn)用vue+ElementUI+echarts前后端交互實(shí)現(xiàn)動態(tài)圓環(huán)圖(推薦)
- Springboot運(yùn)用vue+echarts前后端交互實(shí)現(xiàn)動態(tài)圓環(huán)圖
- Vue實(shí)現(xiàn)圓環(huán)進(jìn)度條的示例
- vue動態(tài)繪制四分之三圓環(huán)圖效果
- vue中使用echarts制作圓環(huán)圖的實(shí)例代碼
- vue使用canvas繪制圓環(huán)
相關(guān)文章
vue左側(cè)菜單,樹形圖遞歸實(shí)現(xiàn)代碼
這篇文章主要介紹了vue左側(cè)菜單,樹形圖遞歸實(shí)現(xiàn)代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-08-08使用element+vuedraggable實(shí)現(xiàn)圖片上傳拖拽排序
這篇文章主要為大家詳細(xì)介紹了使用element+vuedraggable實(shí)現(xiàn)圖片上傳拖拽排序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-04-04基于vue.js仿淘寶收貨地址并設(shè)置默認(rèn)地址的案例分析
這篇文章主要介紹了基于vue.js仿淘寶收貨地址并設(shè)置默認(rèn)地址的案例分析,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-08-08Vue如何使用百度地圖自定義信息窗口InfoWindow的樣式
這篇文章主要介紹了Vue如何使用百度地圖自定義信息窗口InfoWindow的樣式問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03