js仿黑客帝国字母掉落效果代码分享


Posted in Javascript onNovember 08, 2020

看过黑客帝国的朋友或许都对开头的字幕效果很熟悉,自从影片播放以来,网页设计者有不少都在模仿这种字母掉落的效果,而且最后还有文字显现效果“I love you”,你可以稍加修改,在情人节,用来对你的恋人表白哦~

运行效果图:

js仿黑客帝国字母掉落效果代码分享

大家也动手运行一下,                                      ----------------效果演示----------------

为大家分享js仿黑客帝国字母掉落效果代码如下

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS仿黑客帝国字母掉落效果</title>
<style type=text/css>
.matrix{padding-right: 0px; padding-left: 0px; font-size: 10pt; padding-bottom: 0px; margin: 0px; width: 10px; padding-top: 0px; font-family: lucida console, courier, monotype; text-align: center}
</style>
</head>
<body>
<center>JS仿黑客帝国字母掉落效果</center><br><center>

<SCRIPT language=JavaScript type=text/javascript>
var rows=11; // must be an odd number
var speed=50; // lower is faster
var reveal=2; // between 0 and 2 only. The higher, the faster the word appears
var effectalign="default" //enter "center" to center it.
var w3c=document.getElementById && !window.opera;;
var ie45=document.all && !window.opera;
var ma_tab, matemp, ma_bod, ma_row, x, y, columns, ma_txt, ma_cho;
var m_coch=new Array();
var m_copo=new Array();
window.onload=function() {
 if (!w3c && !ie45) return
 var matrix=(w3c)?document.getElementById("matrix"):document.all["matrix"];
 ma_txt=(w3c)?matrix.firstChild.nodeValue:matrix.innerHTML;
 ma_txt=" "+ma_txt+" ";
 columns=ma_txt.length;
 if (w3c) {
 while (matrix.childNodes.length) matrix.removeChild(matrix.childNodes[0]);
 ma_tab=document.createElement("table");
 ma_tab.setAttribute("border", 0);
 ma_tab.setAttribute("align", effectalign);
 ma_tab.style.backgroundColor="#000000";
 ma_bod=document.createElement("tbody");
 for (x=0; x<rows; x++) {
 ma_row=document.createElement("tr");
 for (y=0; y<columns; y++) {
 matemp=document.createElement("td");
 matemp.setAttribute("id", "Mx"+x+"y"+y);
 matemp.className="matrix";
 matemp.appendChild(document.createTextNode(String.fromCharCode(160)));
 ma_row.appendChild(matemp);
 }
 ma_bod.appendChild(ma_row);
 }
 ma_tab.appendChild(ma_bod);
 matrix.appendChild(ma_tab);
 } else {
 ma_tab='<ta'+'ble align="'+effectalign+'" border="0" style="background-color:#000000">';
 for (var x=0; x<rows; x++) {
 ma_tab+='<t'+'r>';
 for (var y=0; y<columns; y++) {
 ma_tab+='<t'+'d class="matrix" id="Mx'+x+'y'+y+'">?</'+'td>';
 }
 ma_tab+='</'+'tr>';
 }
 ma_tab+='</'+'table>';
 matrix.innerHTML=ma_tab;
 }
 ma_cho=ma_txt;
 for (x=0; x<columns; x++) {
 ma_cho+=String.fromCharCode(32+Math.floor(Math.random()*94));
 m_copo[x]=0;
 }
 ma_bod=setInterval("mytricks()", speed);
}

function mytricks() {
 x=0;
 for (y=0; y<columns; y++) {
 x=x+(m_copo[y]==100);
 ma_row=m_copo[y]%100;
 if (ma_row && m_copo[y]<100) {
 if (ma_row<rows+1) {
 if (w3c) {
 matemp=document.getElementById("Mx"+(ma_row-1)+"y"+y);
 matemp.firstChild.nodeValue=m_coch[y];
 }
 else {
 matemp=document.all["Mx"+(ma_row-1)+"y"+y];
 matemp.innerHTML=m_coch[y];
 }
 matemp.style.color="#33ff66";
 matemp.style.fontWeight="bold";
 }
 if (ma_row>1 && ma_row<rows+2) {
 matemp=(w3c)?document.getElementById("Mx"+(ma_row-2)+"y"+y):document.all["Mx"+(ma_row-2)+"y"+y];
 matemp.style.fontWeight="normal";
 matemp.style.color="#00ff00";
 }
 if (ma_row>2) {
 matemp=(w3c)?document.getElementById("Mx"+(ma_row-3)+"y"+y):document.all["Mx"+(ma_row-3)+"y"+y];
 matemp.style.color="#009900";
 }
 if (ma_row<Math.floor(rows/2)+1) m_copo[y]++;
 else if (ma_row==Math.floor(rows/2)+1 && m_coch[y]==ma_txt.charAt(y)) zoomer(y);
 else if (ma_row<rows+2) m_copo[y]++;
 else if (m_copo[y]<100) m_copo[y]=0;
 }
 else if (Math.random()>0.9 && m_copo[y]<100) {
 m_coch[y]=ma_cho.charAt(Math.floor(Math.random()*ma_cho.length));
 m_copo[y]++;
 }
 }
 if (x==columns) clearInterval(ma_bod);
}

function zoomer(ycol) {
 var mtmp, mtem, ytmp;
 if (m_copo[ycol]==Math.floor(rows/2)+1) {

 for (ytmp=0; ytmp<rows; ytmp++) {
 if (w3c) {
 mtmp=document.getElementById("Mx"+ytmp+"y"+ycol);
 mtmp.firstChild.nodeValue=m_coch[ycol];
 }
 else {
 mtmp=document.all["Mx"+ytmp+"y"+ycol];
 mtmp.innerHTML=m_coch[ycol];
 }
 mtmp.style.color="#33ff66";
 mtmp.style.fontWeight="bold";
 }
 if (Math.random()<reveal) {
 mtmp=ma_cho.indexOf(ma_txt.charAt(ycol));
 ma_cho=ma_cho.substring(0, mtmp)+ma_cho.substring(mtmp+1, ma_cho.length);
 }
 if (Math.random()<reveal-1) ma_cho=ma_cho.substring(0, ma_cho.length-1);
 m_copo[ycol]+=199;
 setTimeout("zoomer("+ycol+")", speed);
 }
 else if (m_copo[ycol]>200) {
 if (w3c) {
 mtmp=document.getElementById("Mx"+(m_copo[ycol]-201)+"y"+ycol);
 mtem=document.getElementById("Mx"+(200+rows-m_copo[ycol]--)+"y"+ycol);
 }
 else {
 mtmp=document.all["Mx"+(m_copo[ycol]-201)+"y"+ycol];
 mtem=document.all["Mx"+(200+rows-m_copo[ycol]--)+"y"+ycol];
 }
 mtmp.style.fontWeight="normal";
 mtem.style.fontWeight="normal";
 setTimeout("zoomer("+ycol+")", speed);
 }
 else if (m_copo[ycol]==200) m_copo[ycol]=100+Math.floor(rows/2);
 if (m_copo[ycol]>100 && m_copo[ycol]<200) {
 if (w3c) {
 mtmp=document.getElementById("Mx"+(m_copo[ycol]-101)+"y"+ycol);
 mtmp.firstChild.nodeValue=String.fromCharCode(160);
 mtem=document.getElementById("Mx"+(100+rows-m_copo[ycol]--)+"y"+ycol);
 mtem.firstChild.nodeValue=String.fromCharCode(160);
 }
 else {
 mtmp=document.all["Mx"+(m_copo[ycol]-101)+"y"+ycol];
 mtmp.innerHTML=String.fromCharCode(160);
 mtem=document.all["Mx"+(100+rows-m_copo[ycol]--)+"y"+ycol];
 mtem.innerHTML=String.fromCharCode(160);
 }
 setTimeout("zoomer("+ycol+")", speed);
 }
}
// -->
</SCRIPT>
<div id=matrix>I love u</div>

</center>
</body>
</html>

希望本文所述对大家的javascript程序设计有所帮助。

Javascript 相关文章推荐
CSDN轮换广告图片轮换效果
Mar 27 Javascript
asp.net下使用jquery 的ajax+WebService+json 实现无刷新取后台值的实现代码
Sep 19 Javascript
js 实现日期灵活格式化的小例子
Jul 14 Javascript
Microsfot .NET Framework4.0框架 安装失败的解决方法
Aug 14 Javascript
javascript中Math.random()使用详解
Apr 15 Javascript
JavaScript动态创建div等元素实例讲解
Jan 06 Javascript
jQuery 中ajax异步调用的四种方式
Jun 28 Javascript
基于HTML+CSS+JS实现增加删除修改tab导航特效代码
Aug 05 Javascript
JavaScript定义全局对象的方法示例
Jan 12 Javascript
使用JQuery实现图片轮播效果的实例(推荐)
Oct 24 jQuery
React Native自定义控件底部抽屉菜单的示例
Feb 08 Javascript
layui table 复选框跳页后再回来保持原来选中的状态示例
Oct 26 Javascript
JS模拟并美化的表单控件完整实例
Aug 19 #Javascript
js实现文本框只允许输入数字并限制数字大小的方法
Aug 19 #Javascript
Jquery基础教程之DOM操作
Aug 19 #Javascript
jquery小火箭返回顶部代码分享
Aug 19 #Javascript
JS简单实现城市二级联动选择插件的方法
Aug 19 #Javascript
js实现当前输入框高亮显示的方法
Aug 19 #Javascript
jQuery实现的仿select功能代码
Aug 19 #Javascript
You might like
劣质的PHP代码简化
2010/02/08 PHP
ThinkPHP控制器详解
2015/07/27 PHP
微信支付开发维权通知实例
2016/07/12 PHP
JavaScript中操作字符串小结
2015/05/04 Javascript
javascript实现别踩白块儿小游戏程序
2015/11/22 Javascript
详解Webwork中Action 调用的方法
2016/02/02 Javascript
微信小程序 wx.request方法的异步封装实例详解
2017/05/18 Javascript
微信小程序实现获取自己所处位置的经纬度坐标功能示例
2017/11/30 Javascript
在Vue 中使用Typescript的示例代码
2018/09/10 Javascript
JavaScript数组特性与实践应用深入详解
2018/12/30 Javascript
vue cli3.0结合echarts3.0与地图的使用方法示例
2019/03/26 Javascript
利用Node.js如何实现文件循环覆写
2019/04/05 Javascript
解决layer.confirm选择完之后消息框不消失的问题
2019/09/16 Javascript
vue多个元素的样式选择器问题
2019/11/29 Javascript
js判断在哪个浏览器打开项目的方法
2020/01/21 Javascript
vue中实现点击变成全屏的多种方法
2020/09/27 Javascript
[02:37]2018DOTA2亚洲邀请赛赛前采访-EG篇
2018/04/03 DOTA
Python复制文件操作实例详解
2015/11/10 Python
Django后台获取前端post上传的文件方法
2018/05/28 Python
Python装饰器模式定义与用法分析
2018/08/06 Python
python utc datetime转换为时间戳的方法
2019/01/15 Python
Python字符串中添加、插入特定字符的方法
2019/09/10 Python
python 画条形图(柱状图)实例
2020/04/24 Python
基于python实现MQTT发布订阅过程原理解析
2020/07/27 Python
CSS3实现水平居中、垂直居中、水平垂直居中的实例代码
2020/02/27 HTML / CSS
在canvas上实现元素图片镜像翻转动画效果的方法
2018/03/20 HTML / CSS
HTML5拖拽文件上传的示例代码
2021/03/04 HTML / CSS
Boom手表官网:瑞典手表品牌,设计你的手表
2019/03/11 全球购物
考博自荐信
2013/10/25 职场文书
人事专员岗位职责
2013/11/20 职场文书
护理工作感言
2014/01/16 职场文书
路政管理毕业自荐书范文
2014/02/10 职场文书
人事专员工作职责
2014/02/22 职场文书
纪检干部对照检查材料
2014/08/22 职场文书
2015年纪念“卢沟桥事变”78周年活动方案
2015/05/06 职场文书
2016廉洁从政心得体会
2016/01/19 职场文书