<<  < 2016 - >  >>
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29





//获取浏览器的一个分辨率
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);

  • 标签:js 特效 
  • 发表评论:
    天涯博客欢迎您!