我是新手,我用JS制作了雪花飘落效果。 代码是这样的:
const snowMore = ()=> {
//add more flakes
let moreSnow = document.createElement('i');
moreSnow.classList.add('fa-snowflake');
moreSnow.classList.add('fas');
moreSnow.style.color = 'white';
document.body.appendChild(moreSnow);
//random distance, random speed, random opacity, random size:
moreSnow.style.left = Math.random() * window.innerWidth +'px';
moreSnow.style.opacity = Math.random();
moreSnow.style.fontSize = Math.random()* 10+10+'px';
moreSnow.style.animationDuration = Math.random()* 6+3+'s';
moreSnow.style.animationDelay = Math.random()*3+'s';
}
//activate more flakes
snowMore();
snowMore();
snowMore();
snowMore();
snowMore();
那里还有30个snowMore()
。
有没有一种方法可以调用一次此函数,但是可以获得更多的信息。
谢谢!