Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
.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); }
JavaScript
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), weight: Math.random() * 0.5 + 0.5 }; this.width = options.width || Math.random() * 3; this.lifespan = options.lifespan || Math.round(Math.random() * 20 + 40); this.maxlife = this.lifespan; this.color = options.color || '#fdab23'; this.prev = { x: this.x, y: this.y }; this.update = function(index, array) { this.prev = { x: this.x, y: this.y }; this.x += Math.cos(this.v.direct) * this.v.weight; this.x += Math.cos(this.g.direct) * this.g.weight; this.y += Math.sin(this.v.direct) * this.v.weight; this.y += Math.sin(this.g.direct) * this.g.weight; this.v.weight *= this.v.friction; this.v.direct += this.a.change; (this.v.direct > this.a.max || this.v.direct < this.a.min) && (this.a.change *= -1); 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(this.prev.x, this.prev.y); ctx.stroke(); ctx.closePath(); } this.remove = function(index, array) { array.splice(index, 1); } } function Particles(options) { options = options || {}; this.max = options.max || Math.round(Math.random() * 20 + 10); this.sparks = [...new Array(this.max)].map(() => new Spark(options)); this.update = function() { this.sparks.forEach((s, i) => s.update(i, this.sparks)); } this.render = function(ctx) { this.sparks.forEach(s => s.render(ctx)); } } function Text(options) { options = options || {}; const pool = document.createElement('canvas'); const buffer = pool.getContext('2d'); pool.width = w; buffer.fillStyle = '#000000'; buffer.fillRect(0, 0, pool.width, pool.height); this.size = options.size || 100; this.copy = (options.copy || `Hello!`) + ' '; this.color = options.color || '#fecd96'; this.delay = options.delay || 4; this.basedelay = this.delay; buffer.font = `${this.size}px Comic Sans MS`; this.bound = buffer.measureText(this.copy); this.bound.height = this.size * 1.5; this.x = options.x || w * 0.5 - this.bound.width * 0.5; this.y = options.y || h * 0.5 - this.size * 0.5; buffer.strokeStyle = this.color; buffer.strokeText(this.copy, 0, this.bound.height * 0.8); this.data = buffer.getImageData(0, 0, this.bound.width, this.bound.height); this.index = 0; this.update = function() { if (this.index >= this.bound.width) { this.index = 0; return; } const data = this.data.data; for (let i = this.index * 4; i < data.length; i += (4 * this.data.width)) { const bitmap = data[i] + data[i + 1] + data[i + 2] + data[i + 3]; if (bitmap > 255 && Math.random() > 0.86) { const x = this.x + this.index; const y = this.y + (i / this.bound.width / 4); laser.push(new Laser({ x: x, y: y })); Math.random() > 0.7 && particles.push(new Particles({ x: x, y: y })); } } this.delay-- < 0 && (this.index++ && (this.delay += this.basedelay)); } this.render = function(ctx) { ctx.putImageData(this.data, this.x, this.y, 0, 0, this.index, this.bound.height); } } function loop() { update(); render(); requestAnimationFrame(loop); } function update() { text.update(); laser.forEach((l, i) => l.update(i, laser)); particles.forEach(p => p.update()); } function render() { ctx.globalCompositeOperation = 'source-over'; ctx.globalAlpha = 0.9; ctx.fillStyle = '#000000'; ctx.fillRect(0, 0, w, h); // ctx.globalCompositeOperation = 'screen'; text.render(ctx); laser.forEach(l => l.render(ctx)); particles.forEach(p => p.render(ctx)); } (function () { // canvas = document.getElementById('canvas'); input = document.getElementById('input'); ctx = canvas.getContext('2d'); w = window.innerWidth; h = window.innerHeight; canvas.width = w; canvas.height = h; laser = []; particles = []; // text = new Text({ copy: 'Anh Yêu Em!' }); canvas.addEventListener('click', (e) => { const x = e.clientX; const y = e.clientY; laser.push(new Laser({ x: x, y: y })); particles.push(new Particles({ x: x, y: y })); }); let cb = 0; input.addEventListener('keyup', (e) => { clearTimeout(cb); cb = setTimeout(() => { text = new Text({ copy: input.value }); }, 300); }); // loop(); })()
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>激光文字-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号