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 相关文章推荐
javascript 面向对象继承
Nov 26 Javascript
利用ajaxfileupload插件实现文件上传无刷新的具体方法
Jun 08 Javascript
ie中js创建checkbox默认选中问题探讨
Oct 21 Javascript
使用impress.js制作幻灯片
Sep 09 Javascript
jQuery结合CSS制作动态的下拉菜单
Oct 27 Javascript
JavaScript中值类型和引用类型的区别
Feb 23 Javascript
vue 2.0封装model组件的方法
Aug 03 Javascript
解决betterScroll在vue中存在图片时,出现拉不动的问题
Sep 27 Javascript
angular 未登录状态拦截路由跳转的方法
Oct 09 Javascript
javascript中的相等操作符(==与===区别)
Dec 21 Javascript
jQuery操作元素追加内容示例
Jan 10 jQuery
js canvas实现俄罗斯方块
Oct 11 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
《魔兽争霸3》重制版究竟重制了什么?玩家:这么糊弄真的好吗?
2020/05/04 魔兽争霸
不用iconv库的gb2312与utf-8的互换函数
2006/10/09 PHP
PHP中多维数组的foreach遍历示例
2014/06/13 PHP
PHP计算日期相差天数实例分析
2016/02/23 PHP
php array_udiff_assoc 计算两个数组的差集实例
2016/11/12 PHP
基于jquery+thickbox仿校内登录注册框
2010/06/07 Javascript
web的各种前端打印方法之jquery打印插件PrintArea实现网页打印
2013/01/09 Javascript
jQuery性能优化28条建议你值得借鉴
2013/02/16 Javascript
jQuery图片的展开和收缩实现代码
2013/04/16 Javascript
基于jquery中children()与find()的区别介绍
2013/04/26 Javascript
js和css写一个可以自动隐藏的悬浮框
2014/03/05 Javascript
javascript使用正则获取url上的某个参数
2014/09/04 Javascript
JavaScript前端开发之实现二进制读写操作
2015/11/04 Javascript
详解Node.js:events事件模块
2016/11/24 Javascript
jQuery中layer分页器的使用
2017/03/13 Javascript
浅谈在fetch方法中添加header后遇到的预检请求问题
2017/08/31 Javascript
nodejs高大上的部署方式(PM2)
2018/09/11 NodeJs
vue 插件的方法代码详解
2019/06/06 Javascript
构建Vue大型应用的10个最佳实践(小结)
2019/11/07 Javascript
Python中的choice()方法使用详解
2015/05/15 Python
Python实现通过继承覆盖方法示例
2018/07/02 Python
python看某个模块的版本方法
2018/10/16 Python
基于python实现学生管理系统
2018/10/17 Python
对python读取CT医学图像的实例详解
2019/01/24 Python
解决Pycharm 导入其他文件夹源码的2种方法
2020/02/12 Python
python与c语言的语法有哪些不一样的
2020/09/13 Python
美国男士西装打折店:Jos. A. Bank
2017/11/13 全球购物
SNIDEL官网:日本VIVI杂志人气少女第一品牌
2020/03/12 全球购物
竞聘上岗演讲稿范文
2014/01/10 职场文书
入学申请自荐信范文
2014/02/26 职场文书
捐款通知怎么写
2015/04/24 职场文书
2015年节能减排工作总结
2015/05/14 职场文书
小学生组织委员竞选稿
2015/11/21 职场文书
vue 实现上传组件
2021/05/31 Vue.js
详解Oracle数据库中自带的所有表结构(sql代码)
2021/11/20 Oracle
Java异常处理try catch的基本用法
2021/12/06 Java/Android