当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 基于JavaScript实现飘落星星特效

基于JavaScript实现飘落星星特效

2017年12月12日  | 移动技术网IT编程  | 我要评论

本文实例为大家分享了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> 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网