Skip to content

Commit

Permalink
【添加数字滚动效果】
Browse files Browse the repository at this point in the history
  • Loading branch information
caohongqing committed Aug 12, 2019
1 parent 07a179b commit 8cd0f4a
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions src/views/data/dcontent/dnumber/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>
<div class="number-box">
<div class="title">{{ title }}</div>
<div class="number" :style="styles">{{ dnumber }}</div>
<div class="number" :style="styles">{{ amount }}</div>
</div>
</div>
</template>
Expand All @@ -15,12 +15,56 @@ export default {
name: "dnumber",
props: {
size: [Number, String],
time: {
type: Number,
default: 2
},
title: String,
color: String,
dnumber: Number,
dnumber: {
type: Number,
default: 0
},
icon: String,
dheight: Number
},
data() {
return {
amount: 0
};
},
watch: {
dnumber(val) {
if (val > 0) {
this.numFun(0, val);
}
}
},
methods: {
numFun(startNum, maxNum) {
var that = this;
let numText = startNum;
let golb; // 为了清除requestAnimationFrame
function numSlideFun() {
// 数字动画
//numText+=1; // 速度的计算可以为小数 。数字越大,滚动越快
if (maxNum < 100) {
numText += 1;
} else {
numText += 5;
}
if (numText >= maxNum) {
numText = maxNum;
cancelAnimationFrame(golb);
} else {
golb = requestAnimationFrame(numSlideFun);
}
that.amount = numText;
// console.log(numText)
}
numSlideFun(); // 调用数字动画
}
},
computed: {
styles() {
const style = {};
Expand Down

0 comments on commit 8cd0f4a

Please sign in to comment.