JS生成雪花

<script type="text/javascript">
    (function(){

        function snow(left,height,src){            
            var div = document.createElement("div");
            var img = document.createElement("img");

            div.appendChild(img);
            img.className = "roll";
            img.src = src;
            div.style.left=left+"px";
            div.style.height=height+"px";
            div.className="snow_div";

            document.getElementById("snowzone").appendChild(div);

        setTimeout(function(){
            document.getElementById("snowzone").removeChild(div);
            // console.log(window.innerHeight);
        },5000);

    }

    setInterval(function(){
        var left = Math.random()*document.getElementById("snowzone").offsetWidth;;
        var height = Math.random()*document.getElementById("snowzone").offsetHeight;;
        var ximgUrl = "http://www.yoins.com/templates/default/images/";
        var src = ximgUrl+"s"+Math.floor(Math.random()*2+1)+".png";
        snow(left,height,src);
    },200);

    })();
</script>

 

你可能感兴趣的:(JS生成雪花)