[js实现继承]JS实现好看的飘雪效果的实例代码

时间:2021-08-21  来源:js教程  阅读:



    
    飘雪
    




<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
<script type="text/javascript">
//    窗口大小
    var oPageX=window.screen.width;
    var oPageY=window.screen.height;
    var aSnow=[];
//    雪花模板
    function snow(x,y,xspeed,yspeed,xsin,size){//x水平位置,y垂直位置,xspeed水平步距,yspeed垂直步距,xsin振幅,size雪花大小
        this.node=document.createElement("div");
        this.x=x;
        this.y=y;
        this.xspeed=xspeed;
        this.yspeed=yspeed;
        this.xsin=xsin;
        this.size=size;
        this.createSnow=function(){
            this.node.style.position="absolute";
            this.node.style.top=this.y+"px";
            this.node.style.left=this.x+"px";
            this.node.innerHTML="*";
            document.body.appendChild(this.node);
        };
        this.createSnow();
        this.snowMove=function(){
            this.node.style.top=parseInt(this.node.style.top)+this.yspeed+"px";//垂直方向运动
            this.node.style.left=parseInt(this.node.style.left)+this.xsin*Math.sin(this.xspeed)+"px";
            this.node.style.fontSize=this.size+"px";
//            this.node.style.color="rgb("+Math.ceil(Math.random()*255)+","+Math.ceil(Math.random()*255)+","+Math.ceil(Math.random()*255)+")";
        };
    }
//    创建雪花
    function createSnow(){
        aSnow.push(new snow(Math.random()*oPageX,-50,0.02+Math.random()/10,1+Math.random(),Math.random()*30,20+Math.random()*30));
    }
    setInterval(createSnow,1000);//一秒钟创建一个雪花
//    雪花移动函数
    function snowMove(){
        for(var j=0;joPageY || parseInt(aSnow[j].node.style.left)>oPageX){
                aSnow[j].node.parentNode.removeChild(aSnow[j].node);
                aSnow.splice(j,1);
            }
        }
    }
    setInterval(snowMove,10);
</script>

[js实现继承]JS实现好看的飘雪效果的实例代码

http://m.bbyears.com/wangyezhizuo/137294.html

推荐访问:js实现拖拽 js实现继承的方法
相关阅读 猜你喜欢
本类排行 本类最新