一、HTML代码:

<!DOCTYPE html>
<html>
<head>
<title>Matrix Text - HTML5 Canvas Demo</title>
<script type="text/javascript" src="matrixtext.js"></script>
<style>
@font-face
{
font-family: 'MatrixCode';
src: url("matrix code nfi.otf") format("opentype");
}
html, body
{
background: #000;
margin: 0;
padding: 0;
overflow-x: hidden;
overflow-y: hidden;
}
canvas { font-family: 'MatrixCode'; }
p
{
font-family: 'MatrixCode';
color: #fff;
}
</style>
</head>
<body onload="init();">
<canvas id="theMatrix" width="1280" height="800"> <p>Your browser doesn't support canvas...L0Z3R</p>
</canvas>
</body>
</html>

二、JS代码:

var textStrip = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
var stripCount=90, stripX=new Array(), stripY=new Array(), dY=new Array(), stripFontSize = new Array();
for (var i = 0; i < stripCount; i++) {
stripX[i] = Math.floor(Math.random()*1265);
stripY[i] = -100;
dY[i] = Math.floor(Math.random()*7)+3;
stripFontSize[i] = Math.floor(Math.random()*24)+12;
}
var theColors = ['#cefbe4', '#81ec72', '#5cd646', '#54d13c', '#4ccc32', '#43c728'];
var elem, context, timer;
function drawStrip(x, y) {
for (var k = 0; k <= 20; k++) {
var randChar = textStrip[Math.floor(Math.random()*textStrip.length)];
if (context.fillText) {
switch (k) {
case 0:
context.fillStyle = theColors[0]; break;
case 1:
context.fillStyle = theColors[1]; break;
case 3:
context.fillStyle = theColors[2]; break;
case 7:
context.fillStyle = theColors[3]; break;
case 13:
context.fillStyle = theColors[4]; break;
case 17:
context.fillStyle = theColors[5]; break;
}
context.fillText(randChar, x, y);
}
y -= stripFontSize[k];
}
}
function draw() {
// clear the canvas and set the properties
context.clearRect(0, 0, elem.width, elem.height);
context.shadowOffsetX = context.shadowOffsetY = 0;
context.shadowBlur = 8;
context.shadowColor = '#94f475'; for (var j = 0; j < stripCount; j++) {
context.font = stripFontSize[j]+'px MatrixCode';
context.textBaseline = 'top';
context.textAlign = 'center'; if (stripY[j] > 1358) {
stripX[j] = Math.floor(Math.random()*elem.width);
stripY[j] = -100;
dY[j] = Math.floor(Math.random()*7)+3;
stripFontSize[j] = Math.floor(Math.random()*24)+12;
drawStrip(stripX[j], stripY[j]);
} else drawStrip(stripX[j], stripY[j]); stripY[j] += dY[j];
}
}
function init() {
// get the canvas' id
elem = document.getElementById('theMatrix');
if (!elem || !elem.getContext) return; // get the canvas' context
context = elem.getContext('2d');
if (!context) return; timer = setInterval('draw()', 70);
}

HTML5 Canvas绘文本动画(使用CSS自定义字体)的更多相关文章

  1. HTML5 Canvas水波纹动画特效

    HTML5的Canvas特性非常实用,我们不仅可以在Canvas画布上绘制各种图形,也可以制作绚丽的动画,比如这次介绍的水波纹动画特效.以前我们也分享过一款基于HTML5 WebGL的水波荡漾动画,让 ...

  2. HTML5 Canvas核心技术图形动画与游戏开发 ((美)David Geary) 中文PDF扫描版​

    <html5 canvas核心技术:图形.动画与游戏开发>是html5 canvas领域的标杆之作,也是迄今为止该领域内容最为全面和深入的著作之一,是公认的权威经典.amazon五星级超级 ...

  3. HTML5 Canvas画图与动画学习59例

    HTML5 Canvas画图与动画学习59例 学习HTML5 动画,画图的好资料. HTML5 Canvas画图与动画学习59例

  4. JavaScript 基于HTML5 canvas 获取文本占用的像素宽度

    基于HTML5 canvas 获取文本占用的像素宽度   by:授客 QQ:1033553122 直接上代码   // 获取单行文本的像素宽度 getTextPixelWith(text, fontS ...

  5. html5 canvas在线文本第二步设置(字体边框)等我全部写完,我会写在页面底部

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. 八大疯狂的HTML5 Canvas及WebGL动画效果——8 CRAZY ANIMATIONS WITH WEBGL AND HTML5 CANVAS【收藏】

    HTML5, WebGL and Javascript have changed the way animation used to be. Past few years, we can only a ...

  7. CSS 自定义字体

    移动端如何兼容UI给的字体 [toc] 移动端的默认字体 IOS 默认中文字体是Heiti SC 默认英文字体是Helvetica 默认数字字体是HelveticaNeue Android 默认中文字 ...

  8. CSS自定义字体的实现,前端实现字体压缩

    CSS中使用自定义字体,首先需要下载你需要的字体ttf或者otf文件 这里推荐一个网站:http://www.zitixiazai.org/ /********css中********/ @font- ...

  9. css自定义字体----使用外部字体文件

    css外部自定义字体 给大家分享一个使用的css小技巧!记得收藏呀!相信大家在浏览各种网站会见到各种奇形怪状花里胡哨的文字,还有就是一些浏览器兼容性问题,不会支持一些特殊的字体!给大家分享一个极其简单 ...

随机推荐

  1. Android MultiDex

    出现的原因: 当Android系统安装一个应用的时候,有一步是对Dex进行优化,这个过程有一个专门的工具来处理,叫DexOpt.DexOpt的执行过程是在第一次加载Dex文件的时候执行的.这个过程会生 ...

  2. BZOJ4530: [Bjoi2014]大融合

    Description 小强要在N个孤立的星球上建立起一套通信系统.这套通信系统就是连接N个点的一个树. 这个树的边是一条一条添加上去的.在某个时刻,一条边的负载就是它所在的当前能够 联通的树上路过它 ...

  3. MongoDB 用户配置

    ====[安装]====DOS下切换到文件所在盘符 例如 D:\MongoDB\bin设置数据库保存位置 mongod.exe --dbpath D:\MongoDB\Data [--auth]//用 ...

  4. CentOS 6.5/6.6 安装mysql 5.7 最完整版教程

    Step1: 检测系统是否自带安装mysql # yum list installed | grep mysql Step2: 删除系统自带的mysql及其依赖命令: # yum -y remove ...

  5. XAML parser exception

    To debug xaml exception: Visual Studio -> Debug -> Exception -> Common Language Runtime Exc ...

  6. 处理海量数据的高级排序之——归并排序(C++)

    代码实现                                                                                                 ...

  7. Save vtkImageData to BMP Image 保存vtkImageData为图片

    在VTK中,我们有时候想要保存vtkImageData类的变量到一幅图片,可以使用如下的实例代码: #include <vtkBMPReader.h> #include <vtkBM ...

  8. iBatis in 语句参数传入方法

    刚刚开始在工作中用到iBatis 在用到in去查询或者删除 我本来是传递一个String的参数,但是总是报以下的错误

  9. 无法在提交表单前通过ajax验证解决办法

    博主在一个小项目中,要实现注册表单无刷新验证用户名或密码,但是发现不管怎么样都无法在先通过ajax验证之前不提交表单. 例如:一个简单的验证函数 function check(){ $.post(&q ...

  10. iPhone6分辨率与适配

    iPhone6分辨率与适配 分辨率和像素 经新xcode6模拟器验证(分辨率为pt,像素为真实pixel): iPhone5分辨率320x568,像素640x1136,@2x iPhone6分辨率37 ...