Home > Web Front-end > JS Tutorial > Use js to achieve snowflake falling effect_javascript skills

Use js to achieve snowflake falling effect_javascript skills

WBOY
Release: 2016-05-16 17:24:27
Original
1096 people have browsed it

Today I used html5 canvas and js to write the snowflake effect. Share:

Copy code The code is as follows:


<script><br><br> function start(){<br><br> var array=new Array();<br><br> var canvas=document .getElementById("mycanvas");<br><br> var context=canvas.getContext("2d");<br><br> for(var i=0;i<50;i ){<br><br> var Showsnow=new showsnow();<br><br> array.push(Showsnow);<br><br> }<br><br> <BR> time=setInterval(function (){<br> <br> context.clearRect(0,0,canvas.width,canvas.height);<BR> for(var i=0;i<array.length;i ){<br><br> <BR> array[ i].move();<BR> array[i].draw(context);<br><br> }<br><br> },500);<br><br> }<BR> function showsnow (){<BR> var y=parseInt(Math.random()*50)*10;<br><br> var x=parseInt(Math.random()*80)*10;<br><br> this.draw=function(context){<br><br> <BR> context.font="50px Calibri";<BR> context.fillText("*",x,y);<br><br> <BR> }<BR> this.move=function(){<BR> y =20;<br><br> if(y>600){<br> y=0;<br> }<br> }<br> }<br> </script>








Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template