电子雨html代码

废话不多说下面是代码:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Code</title>

<style>

body{

margin: 0;

overflow: hidden;

}

</style>

</head>

<body>

<canvas id="myCanvas"></canvas>

<script>

const width = document.getElementById("myCanvas").width = screen.availWidth;

const height = document.getElementById("myCanvas").height = screen.availHeight;

const ctx = document.getElementById("myCanvas").getContext("2d");

const arr = Array(Math.ceil(width / 10)).fill(0);

const str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split("");

function rain() {

ctx.fillStyle = "rgba(0,0,0,0.05)";

ctx.fillRect(0, 0, width, height);

ctx.fillStyle = "#0f0";

arr.forEach(function (value, index) {

ctx.fillText(str[Math.floor(Math.random() * str.length)], index * 10, value + 10);

arr[index] = value >= height || value > 8888 * Math.random() ? 0 : value + 10;

});

}

setInterval(rain, 30);

</script>

</body>

</html>

下面是代码效果

代码可以直接复制

如果有啥问题可以问我看到一定会回复大家,如果大家喜欢可以作者点赞和关注

大家的支持是我创作下去的最大动力!

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-01-13 11:04:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-13 11:04:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-13 11:04:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-13 11:04:01       18 阅读

热门阅读

  1. PyQt UI 信号槽函数重复执行问题

    2024-01-13 11:04:01       35 阅读
  2. Spring面试题目

    2024-01-13 11:04:01       31 阅读
  3. vue实现小球掉落

    2024-01-13 11:04:01       41 阅读
  4. opencv在linux上的编译

    2024-01-13 11:04:01       33 阅读
  5. 数据结构之基本数据类型(Python)

    2024-01-13 11:04:01       34 阅读
  6. Vue模板的理解和使用

    2024-01-13 11:04:01       31 阅读
  7. 【C】struct 、struct 指针

    2024-01-13 11:04:01       31 阅读