js实现canvas激光镭射雕刻表白文字动画效果代码
代码语言:html
所属分类:表白
代码描述:js实现canvas激光镭射雕刻表白文字动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
.page-laser-to-text {
position: relative;
overflow: hidden;
}
.page-laser-to-text canvas {
display: block;
}
.page-laser-to-text input {
position: absolute;
bottom: 50px;
left: 0;
right: 0;
display: block;
outline: none;
background-color: rgba(38, 50, 56, 0.2);
color: #ffffff;
border: none;
width: 50%;
min-width: 500px;
max-width: 100%;
margin: auto;
height: 60px;
line-height: 60px;
font-size: 40px;
padding: 0 20px;
}
.page-laser-to-text input:hover, .page-laser-to-text input:focus {
border: 1px solid rgba(38, 50, 56, 0.6);
}
.page-laser-to-text input::-webkit-input-placeholder {
color: rgba(255, 255, 255, 0.1);
}
</style>
</head>
<body>
<div class="page page-laser-to-text">
<input id="input" type="text" maxlength="24" placeholder="I love you!">
<canvas id="canvas"></canvas>
</div>
<script>
let canvas, ctx, w, h, laser, text, particles, input;
function Laser(options) {
options = options || {};
this.lifespan = options.lifespan || Math.round(Math.random() * 20 + 20);
this.maxlife = this.lifespan;
this.color = options.color || '#fd2423';
this.x = options.x || Math.random() * w;
this.y = options.y || Math.random() * h;
this.width = options.width || 2;
this.update = function (index, array) {
this.lifespan > 0 && this.lifespan--;
this.lifespan <= 0 && this.remove(index, array);
};
this.render = function (ctx) {
if (this.lifespan <= 0) return;
ctx.beginPath();
ctx.globalAlpha = this.lifespan / this.maxlife;
ctx.strokeStyle = this.color;
ctx.lineWidth = this.width;
ctx.moveTo(this.x, this.y);
ctx.lineTo(w, this.y);
ctx.stroke();
ctx.closePath();
};
this.remove = function (index, array) {
array.splice(index, 1);
};
}
function Spark(options) {
options = options || {};
this.x = options.x || w * 0.5;
this.y = options.y || h * 0.5;
this.v = options.v || { direct: Math.random() * Math.PI * 2, weight: Math.random() * 10 + 2, friction: 0.94 };
this.a = options.a || { change: Math.random() * 0.2 - 0.1, min: this.v.direct - Math.PI * 0.4, max: this.v.direct + Math.PI * 0.4 };
this.g = options.g || { direct: Math.PI * 0.5 + (Math.random() * 0.4 - 0.2),.........完整代码请登录后点击上方下载按钮下载查看
网友评论0