Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body { background: black; overflow: hidden; /* cursor: none; */ }
JavaScript
window.requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame; var c = document.getElementById("canvas-club"); var w = c.width = window.innerWidth; var h = c.height = window.innerHeight; var ctx = c.getContext("2d"); var maxParticles = 30; var particles = []; var hue = 183; mouse = {}; mouse.size = 200; mouse.x = mouse.tx = w/2; mouse.y = mouse.ty = h/2; var clearColor = "rgba(0, 0, 0, .2)"; function random(min, max){ return Math.random() * (max - min) + min } function distance(x1, y1, x2, y2){ return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ); } function P(){} P.prototype = { init: function(){ this.size = this.origSize = random(10, 100); this.x = random(0, w); this.y = Math.random() > .5 ? -this.size : h + this.size; this.speed = this.origSpeed = random(.01, .03); }, draw: function(){ this.distanceFromMouse = distance(this.x, this.y, mouse.x, mouse.y); ctx.strokeStyle = "hsla("+hue+", 90%, 50%, 1)"; ctx.shadowColor = "hsla("+hue+", 100%, 55%, 1)"; ctx.shadowBlur = this.size * 2; ctx.beginPath(); ctx.moveTo(this.x + this.size * Math.cos(0), this.y + this.size * Math.sin(0)); for(var i=0; i<6; i++){ ctx.lineTo(this.x + this.size * Math.cos(i * 2 * Math.PI / 6), this.y + this.size * Math.sin(i * 2 * Math.PI / 6)); } ctx.closePath(); ctx.lineWidth = 3; ctx.stroke(); this.update(); }, update: function(){ if(this.distanceFromMouse > 20){ this.x += (mouse.x - this.x) * this.speed; this.y += (mouse.y - this.y) * this.speed; if(this.distanceFromMouse < mouse.size){ this.size += (0 - this.size) * this.speed; this.speed += .01; } else { this.size += (this.origSize - this.size) * this.speed; } } else { this.init(); } } } mouse.move = function(){ if(!distance(mouse.x, mouse.y, mouse.tx, mouse.ty) <= .1){ mouse.x += (mouse.tx - mouse.x) * .2; mouse.y += (mouse.ty - mouse.y) * .2; } }; mouse.touches = function(e) { var touches = e.touches; if(touches){ mouse.tx = touches[0].clientX; mouse.ty = touches[0].clientY; } else { mouse.tx = e.clientX; mouse.ty = e.clientY; } e.preventDefault(); }; mouse.mouseleave = function(e){ mouse.tx = w/2; mouse.ty = h/2; }; window.addEventListener("mousemove", mouse.touches); window.addEventListener("touchstart", mouse.touches); window.addEventListener("touchmove", mouse.touches) c.addEventListener("mouseleave", mouse.mouseleave) window.addEventListener("resize", function(){ w = c.width = window.innerWidth; h = c.height = window.innerHeight; }); for(var i=1; i<=maxParticles; i++) { setTimeout(function(){ var p = new P(); p.init(); particles.push(p); }, i * 50); } function anim(){ ctx.fillStyle = clearColor; ctx.shadowColor = clearColor; ctx.shadowBlur = 0; ctx.globalCompositeOperation = "source-over"; ctx.fillRect(0,0,w, h); mouse.move(); for(var i in particles){ var p = particles[i]; p.draw(); } hue++; requestAnimationFrame(anim); } anim();
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>canvas六角型-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号