Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Swimmers
To
Size
To
Speed
To
Stroke Frequency
To
Stroke Depth
To
Mouse Pull Damp.
To
Clear
Set!
Presets:
Flock
Sparkler
Default
css
body { margin:0; min-height:100vh; overflow:hidden; } canvas { background-color:#000; } .info { position:absolute; bottom:0; left:0; z-index:100; background-color:rgba(200,200,200,.8); font-size:80%; } form { position:absolute; top:0; left:0; z-index:100; background-color:rgba(200,200,200,.8); padding:8px; font-size:80%; } form input[type=text] { width:30px; border:1px solid #000; text-align:center; } form button { margin:4px auto; border:1px solid #000; display:block; }
JavaScript
// Create Canvas. var canvas = document.createElement('canvas'); var ctx = canvas.getContext('2d'); var colors = [ 'rgba(69,204,255,.35)', 'rgba(73,232,62,.35)', 'rgba(255,212,50,.35)', 'rgba(232,75,48,.35)', 'rgba(178,67,255,.35)' ]; var colors = [ 'rgba(235,233,177,.35)', 'rgba(193,153,28,.35)', 'rgba(135,118,33,.35)', 'rgba(34,68,85,.35)', 'rgba(143,54,61,.35)' ]; // Configure settings options var config = {}; var particles = []; var settings = document.getElementById('settings'); initSettings(); // Fire the set! button. settings.btnSet.onclick(); var mousePos = [200,200]; // Init. resize(); // Attach canvas. document.body.appendChild(canvas); // Begin drawing. window.requestAnimationFrame(draw); // Sync canvas to window. window.onresize = resize; document.onmousemove = function (e) { mousePos = [e.clientX,e.clientY]; } document.onclick = function (e) { for (var i=0; i
{ for (var i=0; i
this.pos[0]-this.size && hit.pos[0] < this.pos[0]+this.size && hit.pos[1] > this.pos[1]-this.size && hit.pos[1] < this.pos[1]+this.size) { this.collisionCallback(this,hit); } } } this.draw = function (ctx) { ctx.fillStyle = this.color; ctx.beginPath(); ctx.fillRect(this.pos[0]-this.size/2,this.pos[1],this.size,this.size); ctx.stroke(); } } // Drawing. // TODO: This should be part of a Particle Engine system. function draw () { fade(); //clear(); for (var i=0; i
canvas.width || p.pos[1] < 0 || p.pos[1] > canvas.height) { particles.splice(i,1); delete p; continue; } */ var a = mousePos[0]-p.pos[0]; var b = mousePos[1]-p.pos[1]; p.newAngle = angleFromVector(a,b); p.speedMultiplier = 1 + (Math.abs(a)+Math.abs(b)); //console.log(a+b,canvas.width+canvas.height); p.move(); p.draw(ctx); } window.requestAnimationFrame(draw); } function clear () { ctx.beginPath(); ctx.fillStyle = 'rgba(0, 0, 0, 1)'; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.fill(); particles.length = 0; } function fade () { ctx.beginPath(); ctx.fillStyle = 'rgba(0, 0, 0, .3)'; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.fill(); } function resize () { canvas.width = window.innerWidth; canvas.height = window.innerHeight; } /* Common functions */ function angleFromVector(x, y) { // SOHCAHTOA! var a = Math.atan(y/x)*180/Math.PI; if (x < 0 && y < 0) { return a+180; } // If only one axis is negative, so will be the angle, thus an extra // 90deg is added. (90+90, 270+90); else if (x < 0) { return a+180; } else if (y < 0) { return a+360; } return a; } function rand(min, max) { return Math.random()*(max-min)+min; } function randColor(min, max) { var r = Math.floor(rand(min,max)), g = Math.floor(rand(min,max)), b = Math.floor(rand(min,max)); return 'rgba('+r+','+g+','+b+',1)'; } // Settings. function initSettings () { settings.btnSet.onclick = function () { config.num = [ parseFloat(settings.inNumMin.value), parseFloat(settings.inNumMax.value) ]; config.size = [ parseFloat(settings.inSizeMin.value), parseFloat(settings.inSizeMax.value) ]; config.speed = [ parseFloat(settings.inSpeedMin.value), parseFloat(settings.inSpeedMax.value) ]; config.curve = [ parseFloat(settings.inCurveMin.value), parseFloat(settings.inCurveMax.value) ]; config.stroke = [ parseFloat(settings.inStrokeMin.value), parseFloat(settings.inStrokeMax.value) ]; config.pull = [ parseFloat(settings.inPullMin.value), parseFloat(settings.inPullMax.value) ]; clear(); start(); } // Configure clear button settings.btnClear.onclick = clear; // Presets. settings.preset0.onclick = function () { preset({ inNumMin:100, inNumMax:100, inSizeMin:5, inSizeMax:8, inSpeedMin:1, inSpeedMax:6, inStrokeMin:10, inStrokeMax:20, inCurveMin:-2, inCurveMax:2, inPullMin:100, inPullMax:300 }); }; settings.preset1.onclick = function () { preset({ inNumMin:1000, inNumMax:1000, inSizeMin:6, inSizeMax:6, inSpeedMin:5, inSpeedMax:5, inStrokeMin:10, inStrokeMax:20, inCurveMin:-2, inCurveMax:2, inPullMin:50, inPullMax:50 }); }; settings.preset2.onclick = function () { preset({ inNumMin:200, inNumMax:200, inSizeMin:8, inSizeMax:8, inSpeedMin:1, inSpeedMax:6, inStrokeMin:10, inStrokeMax:20, inCurveMin:-5, inCurveMax:5, inPullMin:10, inPullMax:10 }); }; } function preset (options) { for (var i in options) { if (settings[i].type == 'checkbox') { settings[i].checked = options[i]; continue; } settings[i].value = options[i]; } clear(); settings.btnSet.onclick(); }
粒子
时间
文字
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号