tweenMax+如何让数字由初始值动画到结束的值
html:
<div class="wz1">0</div>
css:
.wz1{
width: 114px;
height: 30px;
position: absolute;
top: 40px;
left: 75px;
color:#fff;
font-size: 30px;
}
js:(写在预加载函数中)
let val2 = document.getElementsByClassName("wz2")[0];
animateNum(val2, 8397, 0);
// 初始值 结束值 几个小数点
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
});
}
如果报错了,继续往下拉--
记得引入tweenmax.js的插件哦