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>

 

posted @ 2015-12-28 09:53  百宝箱  阅读(243)  评论(0编辑  收藏  举报