//获取浏览器的一个分辨率
var s=screen;
var w=s.width;
var h=s.height;
var canvas=***.getElementById("canvas");
//获取画布
var ctx=canvas.getContext("2d");
//动态添加画布的高度 宽度
canvas.width=w;
canvas.height=h;
// ------***(w+"------"+h);
var str="我在一次机缘巧合的场合认识了我现在的爱人严文丽,有她对我的鼓励,每天奋斗到三点我也不觉得累,^o^";
var fontSize=22;
//列 Math.floor 向下取整
var cols=Math.floor(w/fontSize); // 59
// -----***(cols);
//定义一个数组 存放Y坐标一次
var drops=[];
for(var i=0;i<cols;i++)
{
drops.push(0);
}
//绘画
draw(){
//rgba(红绿蓝,透明度) rgb 红绿蓝 ctx.fillStyle="rgba(0,0,0,0.5)";
ctx.fillStyle="rgba(0,0,0,0.09)";
ctx.fillRect(0,0,w,h);
ctx.fillStyle="green";
ctx.font="600,"+fontSize+"px 微软雅黑";
for(var i=0;i<cols;i++)
{
var index=Math.floor(Math.random()*str.length);
//动态定义字体的位置
var x=i*fontSize;
var y=drops[i]*fontSize;
//添加文字 fillText(str,x,y) y++
ctx.fillText(str[index],x,y);
if(y>canvas.height && Math.random()>0.89)
{
drops[i]=0;
}
drops[i]++;
}
//---console.log(y);
};
draw();
//定时器
setInterval(draw,33);