Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
jQuery
www.jq22.com
css
body { padding: 0px; margin: 0px; background-color: #252525; } .hidden { display: none; } #spring-text { position: absolute; }
JavaScript
// WRITTEN BY TRUMAN HEBERLE var COLOR = "#52E6FF" var MESSAGE = document.getElementById("title-desktop").textContent; var FONT_SIZE = 100; var AMOUNT = 2000; var SIZE = 2; var INITIAL_DISPLACEMENT = 500; var INITIAL_VELOCITY = 5; var VELOCITY_RETENTION = 0.95; var SETTLE_SPEED = 1; var FLEE_SPEED = 1; var FLEE_DISTANCE = 50; var FLEE = true; var SCATTER_VELOCITY = 3; var SCATTER = true; if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { // Mobile MESSAGE = document.getElementById("title-mobile").textContent; FONT_SIZE = 50; AMOUNT = 300; SIZE = 2; INITIAL_DISPLACEMENT = 100; SETTLE_SPEED = 1; FLEE = false; SCATTER_VELOCITY = 2; } const canvas = document.getElementById("spring-text"); const ctx = canvas.getContext("2d"); var POINTS = []; var MOUSE = { x: 0, y: 0 } function Point(x,y,r,g,b,a) { var angle = Math.random() * 6.28; this.dest_x = x; this.dest_y = y; this.original_r = r; this.original_g = g; this.original_a = a; this.x = canvas.width/2 - x + (Math.random() - 0.5) * INITIAL_DISPLACEMENT; this.y = canvas.height/2 - y + (Math.random() - 0.5) * INITIAL_DISPLACEMENT; this.velx = INITIAL_VELOCITY * Math.cos(angle); this.vely = INITIAL_VELOCITY * Math.sin(angle); this.target_x = canvas.width/2 - x; this.target_y = canvas.height/2 - y; this.r = r; this.g = g; this.b = b; this.a = a; this.getX = function() { return this.x; } this.getY = function() { return this.y; } this.resetTarget = function () { this.target_x = canvas.width/2 - this.dest_x; this.target_y = canvas.height/2 - this.dest_y; } this.fleeFrom = function(x, y) { this.velx -= ((MOUSE.x - this.x) * FLEE_SPEED / 10); this.vely -= ((MOUSE.y - this.y) * FLEE_SPEED / 10); } this.settleTo = function(x, y) { this.velx += ((this.target_x - this.x) * SETTLE_SPEED / 100); this.vely += ((this.target_y - this.y) * SETTLE_SPEED / 100); this.velx -= this.velx * (1-VELOCITY_RETENTION); this.vely -= this.vely * (1-VELOCITY_RETENTION); } this.scatter = function() { var unit = this.unitVecToMouse(); var vel = SCATTER_VELOCITY * 10 * (0.5 + Math.random() / 2); this.velx = -unit.x * vel; this.vely = -unit.y * vel; } this.move = function() { if (this.distanceToMouse() <= FLEE_DISTANCE) { this.fleeFrom(MOUSE.x, MOUSE.y); } else { this.settleTo(this.target_x, this.target_y); } if (this.x + this.velx < 0 || this.x + this.velx >= canvas.width) { this.velx *= -1; } if (this.y + this.vely < 0 || this.y + this.vely >= canvas.height) { this.vely *= -1; } this.x += this.velx; this.y += this.vely; } this.distanceToTarget = function() { return this.distanceTo(this.target_x, this.target_y); } this.distanceToMouse = function() { return this.distanceTo(MOUSE.x, MOUSE.y); } this.distanceTo = function(x, y) { return Math.sqrt((x - this.x)*(x - this.x) + (y - this.y)*(y - this.y)); } this.unitVecToTarget = function() { return this.unitVecTo(this.target_x, this.target_y); } this.unitVecToMouse = function() { return this.unitVecTo(MOUSE.x, MOUSE.y); } this.unitVecTo = function(x, y) { var dx = x - this.x; var dy = y - this.y; return { x: dx / Math.sqrt(dx*dx + dy*dy), y: dy / Math.sqrt(dx*dx + dy*dy) }; } } window.addEventListener("resize", function() { resizeCanvas() adjustText() }); if (FLEE) { window.addEventListener("mousemove", function(event) { MOUSE.x = event.clientX; MOUSE.y = event.clientY; }); } if (SCATTER) { window.addEventListener("click", function(event) { MOUSE.x = event.clientX; MOUSE.y = event.clientY; for (var i=0; i
粒子
时间
文字
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号