<div class="main pop-box"></div>
css:
@keyframes wind{
0% {
bottom: 100%;
transform: rotate(0deg);
}
100% {
transform: rotate(-90deg);
bottom: -10%;
}
}
//可添加不同速度
.speed1{
position: absolute;
animation: wind 5s linear;
}
js:
//imgs=[]
timeFun(imgs){
var self = this
var len = imgs.length
this.popTimer = setInterval(function() {
var left = Math.random() * window.innerWidth;
var top =0;
var index = Math.floor(Math.random() * len)
var src = imgs[index]
self.wind(left, top, src);
}, 250);
},
wind(left, top, src) {
var img = document.createElement("img");
img.className = "speed1"
img.src = src;
img.style.width = Math.random()*(2.2-0.6)+0.6 + "rem";
img.style.height = "auto";
img.style.left = left + "px";
img.style.bottom = "100%";
document.getElementsByClassName("pop-box")[0].appendChild(img);
setTimeout(function() {
document.getElementsByClassName("pop-box")[0].removeChild(img);
}, 10000);
}
本文介绍了一种使用CSS动画实现风动效果的方法,并通过JavaScript动态生成图片粒子,使其随风飘动。具体实现了动画的速度变化及图片粒子的随机生成与移除。
3574

被折叠的 条评论
为什么被折叠?



