<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>snow</title>
<style>
*{margin:0;padding:0;}
html{
height:100%;
}
body{
height:100%;
/*background-color:rgba (0, 0, 0,1); body more Special */
Background-color:black;
Overflow:hidden;
}
/*.one{
}*/
</style>
<body>
<!--<div class= "one" >
</div>-->
<script>
The visible height of the var h=document.body.offsetheight;/*body */
Alert (h);
function Flake () {
Create a picture
var f=document.createelement (' img ');
Get Document width
var w=document.documentelement.clientwidth;
Get Document High
In fact, the height and width of the HTML above are inherited from the document.
var h=document.documentelement.clientheight;
Define a randomly occurring picture
var left=math.random () *w;
var top=math.random () *h;
Add a path to a picture let him show it when the function flake is executed.
F.src= ' G ' +math.ceil (Math.random ()) + '. jpg ';
f.style.position= ' absolute ';
f.style.z-index= ' 1 ';
f.style.left=left+ ' px ';/* string concatenation */
f.style.top=top+ ' px ';
f.style.transform= ' Scale (' +math.random () + ') ';
The created IMG must be added to the body to display
Document.body.appendChild (f);
function down () {
Left+=math.random ();
Top+=math.random ();
if (left>w) left=-20;
if (top>h) top=-20;
f.style.left=left+ ' px ';
f.style.top=top+ ' px ';
}
SetInterval (down,20);
}
for (Var i=0;i<20;i++) {
New Flake ();
}
</script>
</body>
20160612 HTML5 Learning Code (Snowflake effect)