您好,欢迎访问一九零五行业门户网

JavaScript如何实现飘落星星特效的实例代码详解

这篇文章主要为大家详细介绍了基于javascript实现飘落星星特效,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了js飘落星星特效的具体代码,供大家参考,具体内容如下
1.效果图
2.代码
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>title</title> <style> img{ position: absolute; } body { background-image: url(img/bg.jpg); background-size: 100%; } </style> <script> function star() { this.speed=10; this.img=new image(); this.img.src="img/star"+parseint(math.random()*4+1)+".png"; this.img.style.width=50+'px'; this.img.style.height=50+'px'; this.img.style.top=math.random()*window.innerheight+1+'px'; this.img.style.left=math.random()*window.innerwidth+1+'px'; document.body.appendchild(this.img); } star.prototype.slip=function () { var that=this; function move() { that.img.style.top=that.img.offsettop+that.speed+'px'; console.log(that.img.offsettop+"star"); console.log(window.innerheight+"window"); if(that.img.offsettop>window.innerheight){ clearinterval(sh); that.img.style.height=0; that.img.style.width=0; } } var sh=setinterval(move,100); } setinterval(function () { for(var i=1;i<5;i++){ new star().slip(); } },1000) </script> </head> <body> </body> </html>
以上就是javascript如何实现飘落星星特效的实例代码详解的详细内容。
其它类似信息

推荐信息