写一个前端页面,要求每次刷新都可以生成1~10大小的矩阵动画,每行是从0开始,生成随机的0-10的居中,类似这样 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
时间: 2024-02-21 21:01:02 浏览: 21
这里是一个稍微修改了一下的示例,生成一个10x4的矩阵,每行从0开始,每个单元格随机生成0-10的数字,并且数字居中显示:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Matrix Animation</title>
<style type="text/css">
/* 设置单元格样式 */
td {
width: 50px;
height: 50px;
text-align: center;
font-size: 24px;
font-weight: bold;
color: #0f0;
background-color: #000;
}
</style>
</head>
<body>
<table id="matrix"></table>
<script type="text/javascript">
// 获取表格元素
var table = document.getElementById("matrix");
// 生成矩阵
for (var i = 0; i < 4; i++) {
var row = table.insertRow(i);
for (var j = 0; j < 10; j++) {
var cell = row.insertCell(j);
cell.innerHTML = (j + Math.floor(Math.random() * 11)) % 11;
}
}
</script>
</body>
</html>
```
在这个示例中,我们修改了生成表格的循环,每行从0开始,每个单元格随机生成0-10的数字,并使用`(j + Math.floor(Math.random() * 11)) % 11`计算出每个单元格的值,以保证数字循环出现。