js實現雪花飄落效果的代碼


使用js實現雪花飄落的效果,用html5繪布加js寫的雪花飄效果 。

代碼:

<html>
<head>
<script>
/**
* js與html5實現的雪花飄落效果
* edit:www.jbxue.com
*/

function start(){

var array=new Array();

var canvas=document.getElementById("mycanvas");

var context=canvas.getContext("2d");

for(var i=0;i<50;i++){

var Showsnow=new showsnow();

array.push(Showsnow);

}


time=setInterval(function (){

context.clearRect(0,0,canvas.width,canvas.height);
for(var i=0;i<array.length;i++){


array[i].move();
array[i].draw(context);

}

},500);

}
function showsnow(){
var y=parseInt(Math.random()*50)*10;

var x=parseInt(Math.random()*80)*10;

this.draw=function(context){


context.font="50px Calibri";
context.fillText("*",x,y);


}
this.move=function(){
y+=20;

if(y>600){
y=0;
}
}
}
</script>
</head>

<body>
<input type="button" value="start" onclick="start()" />
<br/>
<canvas id="mycanvas" height="600px" width="600px" style="border: 3px solid blue"></canvas>
</body>
</html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM