3 Star 4 Fork 1

huangliusong/HTML5Canvas知乎登录页面动态线条背景动画代码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index2.html 4.60 KB
一键复制 编辑 原始数据 按行查看 历史
huangliusong 提交于 2018-09-21 09:23 . 新建 index2.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>会议管理系统登陆</title>
<!-- for HTML5 -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="/TouchDemo/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<!-- 最新的 Bootstrap 核心 JavaScript 文件text-align: center; -->
<script src="/TouchDemo/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<style type="text/css">
body{
background: #F7FAFC;
overflow: hidden;
background: #fff;
}
</style>
</head>
<body onload='document.f.username.focus();'>
<form name="f" action="/TouchDemo/login" method="POST" style="position: absolute;left: 35%; top: 10px">
<div style="width: 400px; margin: 0 auto; margin-top: 200px;">
<h3 class="text-info" style="text-align:center">会议管理系统登陆</h3>
<table>
<tbody>
<tr>
<div class="form-group text-primary">
<label class="control-label" for="inputSuccess1">用戶名:</label> <input
type="text" name="username" value="" class="form-control " />
</div>
</tr>
<tr>
<td></td>
<td></td>
<div class="form-group text-primary">
<label class="control-label" for="inputSuccess1">密码:</label> <input
type="password" name="password" class="form-control " />
</div>
</tr>
<tr>
<td colspan="2"><input name="submit" type="submit" value="登陆"
class="btn btn-info" /></td>
</tr>
</tbody>
</table>
</div>
</form>
<canvas id="Mycanvas"></canvas>
<script>
//定义画布宽高和生成点的个数
var WIDTH = window.innerWidth, HEIGHT = window.innerHeight, POINT = 38;
var canvas = document.getElementById('Mycanvas');
canvas.width = WIDTH,
canvas.height = HEIGHT;
var context = canvas.getContext('2d');
context.strokeStyle = 'rgba(0,0,0,0.02)',
context.strokeWidth = 1,
context.fillStyle = 'rgba(0,0,0,0.05)';
var circleArr = [];
//线条:开始xy坐标,结束xy坐标,线条透明度
function Line (x, y, _x, _y, o) {
this.beginX = x,
this.beginY = y,
this.closeX = _x,
this.closeY = _y,
this.o = o;
}
//点:圆心xy坐标,半径,每帧移动xy的距离
function Circle (x, y, r, moveX, moveY) {
this.x = x,
this.y = y,
this.r = r,
this.moveX = moveX,
this.moveY = moveY;
}
//生成max和min之间的随机数
function num (max, _min) {
var min = arguments[1] || 0;
return Math.floor(Math.random()*(max-min+1)+min);
}
// 绘制原点
function drawCricle (cxt, x, y, r, moveX, moveY) {
var circle = new Circle(x, y, r, moveX, moveY)
cxt.beginPath()
cxt.arc(circle.x, circle.y, circle.r, 0, 2*Math.PI)
cxt.closePath()
cxt.fill();
return circle;
}
//绘制线条
function drawLine (cxt, x, y, _x, _y, o) {
var line = new Line(x, y, _x, _y, o)
cxt.beginPath()
cxt.strokeStyle = 'rgba(0,0,0,'+ o +')'
cxt.moveTo(line.beginX, line.beginY)
cxt.lineTo(line.closeX, line.closeY)
cxt.closePath()
cxt.stroke();
}
//初始化生成原点
function init () {
circleArr = [];
for (var i = 0; i < POINT; i++) {
circleArr.push(drawCricle(context, num(WIDTH), num(HEIGHT), num(15, 2), num(10, -10)/40, num(10, -10)/40));
}
draw();
}
//每帧绘制
function draw () {
context.clearRect(0,0,canvas.width, canvas.height);
for (var i = 0; i < POINT; i++) {
drawCricle(context, circleArr[i].x, circleArr[i].y, circleArr[i].r);
}
for (var i = 0; i < POINT; i++) {
for (var j = 0; j < POINT; j++) {
if (i + j < POINT) {
var A = Math.abs(circleArr[i+j].x - circleArr[i].x),
B = Math.abs(circleArr[i+j].y - circleArr[i].y);
var lineLength = Math.sqrt(A*A + B*B);
var C = 1/lineLength*7-0.009;
var lineOpacity = C > 0.03 ? 0.03 : C;
if (lineOpacity > 0) {
drawLine(context, circleArr[i].x, circleArr[i].y, circleArr[i+j].x, circleArr[i+j].y, lineOpacity);
}
}
}
}
}
//调用执行
window.onload = function () {
init();
setInterval(function () {
for (var i = 0; i < POINT; i++) {
var cir = circleArr[i];
cir.x += cir.moveX;
cir.y += cir.moveY;
if (cir.x > WIDTH) cir.x = 0;
else if (cir.x < 0) cir.x = WIDTH;
if (cir.y > HEIGHT) cir.y = 0;
else if (cir.y < 0) cir.y = HEIGHT;
}
draw();
}, 16);
}
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/huangliusong/gh5.git
git@gitee.com:huangliusong/gh5.git
huangliusong
gh5
HTML5Canvas知乎登录页面动态线条背景动画代码
master

搜索帮助