js实现黑客代码雨效果
Posted 流楚丶格念
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js实现黑客代码雨效果相关的知识,希望对你有一定的参考价值。
效果
他是动的哈,上传gif太大,CSDN不让传,所以只放了图片
代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>黑客</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body {
background: black;
}
canvas {
display: block;
}
</style>
</head>
<body>
<canvas id="c"></canvas>
<script type="text/javascript">
var c = document.getElementById("c");
var ctx = c.getContext("2d");
c.height = window.innerHeight;
c.width = window.innerWidth;
var chinese = "01011001011";
chinese = chinese.split("");
var font_size = 10;
var columns = c.width / font_size;
var drops = [];
for (var i = 0; i < columns; i++)
drops[i] = 1;
function draw() {
ctx.fillStyle = "rgba(0,0,0,0.05)";
ctx.fillRect(0, 0, c.width, c.height);
ctx.fillStyle = "#0F0";
ctx.font = font_size + "px arial";
for (var i = 0; i < drops.length; i++) {
var text = chinese[Math.floor(Math.random() * chinese.length)];
ctx.fillText(text, i * font_size, drops[i] * font_size);
if (drops[i] * font_size > c.height && Math.random() > 0.975)
drops[i] = 0;
drops[i]++;
}
}
setInterval(draw, 50);
</script>
</body>
</html>
以上是关于js实现黑客代码雨效果的主要内容,如果未能解决你的问题,请参考以下文章