//获取最大值与最小值之间的随机数
randomNum(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
},
//定义好动画,随机获取class
getLParams() {
const classList = [
'animation-l1',
'animation-l2',
'animation-l3',
];
const className = classList[this.randomNum(0, classList.length)];
return {
animate: className,
id: `${new Date().getTime()}-likes`
};
},
//点击即执行一次,如果要执行多次,可以使用setInterval
immediately(){
//单次
new Promise(reslove => {
const params = this.getLParams();
this.likesData.push(params);
this.skyIndex ++;
//2.4s播放完毕
setTimeout(() => {
reslove(params);
}, 2400);
}).then(res => {
this.likesData.shift();
});
//多次-举个例子:执行10次
let a = setInterval(()=>{
if(this.skyIndex >= 10){
clearInterval(a)
setTimeout(() => {
this.skyIndex = 0
...
}, 2400);
}else{
//复制单次
...
}
},100)
},
css就根据项目需求来写
.animation-l1{
-webkit-animation:lottery1 2s;
animation:lottery1 2s;
animation-fill-mode:forwards;
}
.animation-l2{
-webkit-animation:lottery2 2s;
animation:lottery2 2s;
animation-fill-mode:forwards;
}
.animation-l3{
-webkit-animation:lottery3 2s;
animation:lottery3 2s;
animation-fill-mode:forwards;
}
@keyframes lottery1{}
@keyframes lottery2{}
@keyframes lottery3{}