Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body{ margin: 0; background-color: #1D1E22; } canvas{ display: block; }
JavaScript
const ctx = c.getContext("2d"); const rAF = requestAnimationFrame; const m = { x: 0, y: 0, a: 0, e: false }; class Letters { constructor(x, y, char, font, color, radius) { this.x = x; this.y = y; this.char = char; this.font = font; this.color = color; this.radius = 0; this.oriRad = radius; this.i = 20; this.maxSize = 30; this.minSize = 20; this.v = 5; this.dist = 0; this.friction = 0.9 this.K = 0.2 this.vel = { x: 0, y: 0 }; this.o = { x: 0, y: 0, a: 0 }; } angleChars() { if (this.radius < this.oriRad) this.radius += this.v; const dx = m.x - this.x; const dy = m.y - this.y; this.dist = Math.hypot(dx, dy); m.a = Math.atan2(dy, dx); const ax = Math.cos(m.a) * this.radius; const ay = Math.sin(m.a) * this.radius; this.o.x = lerp(ax, this.o.x, 0.1); this.o.y = lerp(ay, this.o.y, 0.1); this.dist < this.radius + 10 ? this.i < this.maxSize ? ((this.dist = this.radius), (this.i += this.v - 4), (this.font = `600 ${this.i}px Arial`)) : null : this.i > this.minSize ? ((this.i -= this.v - 4), (this.font = `600 ${this.i}px Arial`)) : null; } onMouseLeave() { // Hooke's law for linear springs const forceX = this.K * (0 - this.o.x) const forceY = this.K * (0 - this.o.y) this.vel.x += forceX; this.vel.y += forceY; this.vel.x *= this.friction this.vel.y *= this.friction this.o.x += this.vel.x; this.o.y += this.vel.y; if (this.i > this.minSize) { this.i -= this.v - 4; this.font = `600 ${this.i}px Arial`; } } update(ctx) { m.e ? this.angleChars() : this.onMouseLeave(); this.draw(ctx); } draw(ctx) { ctx.save(); ctx.setTransform(1, 0, 0, 1, this.o.x, this.o.y); ctx.fillStyle = this.color; ctx.textAlign = "center"; ctx.textBaseline = "middle"; ctx.font = this.font; ctx.fillText(this.char, this.x, this.y); ctx.restore(); } } let letters; const init = () => { c.width = window.innerWidth; c.height = window.innerHeight; letters = []; const chars = ["A", "L", "A", "I", "N"]; const colors = ["#02d2d6", "#b125d1", "#fea064", "#00a8e8", "#fb89ef"]; const colorLength = colors.length; const charLength = chars.length; const gridLength = 5; const radius = Math.min(c.width, c.height) / (gridLength + 1) / 2; const font = "600 20px Arial"; for (let i = 0; i < gridLength; i++) { for (let j = 0; j < gridLength; j++) { const x = c.width / (gridLength + 1) * (j + 1); const y = c.height / (gridLength + 1) * (i + 1); const color = randomValue(colors, colorLength); const char = randomValue(chars, charLength); letters.push(new Letters(x, y, char, font, color, radius)); } } }; const lerp = (end, start, p) => p * (end - start) + start; const randomValue = (array, length) => array[Math.floor(Math.random() * length)]; const animate = () => { ctx.clearRect(0, 0, c.width, c.height); for (let letter of letters) { letter.update(ctx); } rAF(animate); }; init(); animate(); window.addEventListener("resize", init); c.addEventListener("mousemove", e => { m.x = e.x; m.y = e.y; }); c.addEventListener("mouseenter", () => { m.e = true; }); c.addEventListener("mouseleave", () => { m.e = false; });
粒子
时间
文字
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号