用TweenMax.js动画让数字动起来
html:
<div class="val2">0</div>
js:
let val2 = document.getElementsByClassName("val2")[0];
animateNum(val2, 36.3163, 4);
// 初始值 结束值 几个小数点
function animateNum(dom, val, dot){
let obj = {num1: dom.innerHTML};
TweenMax.to(obj, 1, {
num1: val,
onUpdate:function(){
dom.innerHTML=obj.num1.toFixed(dot);
},
delay: 0.1
});
}
还有最重要的去官网下载然后在引入
<script src="./lib/TweenMax.min.js"></script>
ok.....