进度条效果:
进度条颜色是渐变色,可以通过传值自定义
进度条带有动画效果 使用gsap实现补间动画
进度条有默认背景色
进度条宽度根据总数和当前数据计算百分比
数字居右展示
演示地址
使用组件
<template>
<div class="list">
<div class="listItem wow fadeInRight" :data-wow-delay="1.2+0.3*index+'s'"
v-for="(item,index) in list"
:key="index">
<progressBar :total="total" :item="item"></progressBar>
</div>
</div>
</template>
<script>
import progressBar from "./progressBar.vue";
export default {
data() {
return {
list: [
{
title: '中文数据库(个)',
num: 2000,
id: 'teacherTypeFullTime'
},
{
title: '外文数据库(个)',
num: 210,
id: 'teacherTypeOffCampus'
},
{
title: '电子资源总量(个)',
num: 2210,
id: 'teacherTypeGraduateDegree'
}]
}
},
props: {
title: {
type: String,
default() {
return '';
}
}
},
components: {progressBar},
computed: {
total: function () {
var total = 0
this.list.forEach((type) => {
total = total + type.num
});
return total
}
},
mounted() {
var that = this;
},
methods: {},
filters: {},
watch: {}
}
</script>
<style lang="scss" scoped>
.list {
width: calc(60% - 30px);
margin-left: 0px;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
flex-direction: column;
align-content: flex-start;
height: 100%;
.listItem {
font-size: 14px;
display: flex;
justify-content: flex-start;
align-items: flex-start;
flex-wrap: nowrap;
flex-direction: column;
align-content: flex-start;
height: 30%;
width: 100%;
}
}
</style>
组件代码
/**
* @Author: 858834013@qq.com
* @Name: progressBar
* @Date: 2023年04月17日
* @Desc: 进度条效果
*/
<template>
<div class="progressBarBody">
<div class="progressBarBodyTitle">{{ item.title }}</div>
<div class="progressBar">
<div class="progressBarInner"
:style="{background: 'linear-gradient(180deg, '+item.color+' 0%, '+item.color2+' 100%)'}"
ref="progressBarInner"></div>
<div class="line"></div>
<div class="Num"><span>{{ item.num }}</span></div>
</div>
</div>
</template>
<script>
import gsap from "gsap";
export default {
name: "progressBarBody",
props: {
item: {
type: Object,
default() {
return {}
}
},
total: {
type: Number,
default() {
return 0
}
},
},
data() {
return {}
},
computed: {
width: function () {
return (this.item.num / this.total).toFixed(2) * 100
}
},
mounted() {
setTimeout(() => {
gsap.to(this.$refs.progressBarInner, {
duration: 1.5, width: this.width + '%', onComplete: () => {
console.log('动画完成')
}
})
}, 1000)
},
methods: {}
}
</script>
<style lang="scss" scoped>
.progressBarBody {
display: flex;
justify-content: flex-start;
align-items: flex-start;
flex-wrap: nowrap;
flex-direction: column;
align-content: flex-start;
width: calc(100% - 0px);
.Num {
font-size: 14px;
font-family: DIN-Bold, DIN;
font-weight: bold;
color: #FFFFFF;
position: absolute;
width: 100%;
display: flex;
justify-content: flex-end;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
span {
margin-right: 6px;
}
}
.progressBarBodyTitle {
font-size: 13px;
font-family: PingFang SC-Bold, PingFang SC;
font-weight: bold;
color: #D7E7FF;
height: 35px;
display: flex;
justify-content: flex-start;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
}
.progressBar {
width: 100%;
height: 13px;
background: linear-gradient(180deg, rgba(#04CEF7, 0.2) 0%, rgba(#1263FF, 0.2) 100%);
display: flex;
justify-content: flex-start;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
position: relative;
}
}
.progressBarInner {
height: 13px;
background: linear-gradient(180deg, #04CEF7 0%, #1263FF 100%);
opacity: 1;
width: 0%;
max-width: calc(100% - 0px);
}
.progressBarl {
display: flex;
justify-content: flex-start;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
}
.line {
height: 15px;
width: 2px;
background: #04CEF7;
opacity: 1;
margin-left: 2px;
}
</style>