Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body{ margin:0; } #wrapper{ position: absolute; width:100%; height:100%; overflow:hidden; } canvas{ background:#000; }
JavaScript
$(function() { var stageWidth; var stageHeight; var context = $("canvas")[0].getContext('2d'); var objectList; var timeout; var isMouseOnStage = false; var mouseX = 0; var mouseY = 0; var cellXCount; var cellYCount; var prms = { fps: 60, objectDistance: 40, objectRotationV: Math.PI * .01, objectRadius: 10, animationDelta: 0.005, animationSpringK: 0.03, animationFriction: 0.25, mouseForce: 80 } $(window).resize(reset); $("#wrapper").bind("mousemove", function(e) { mouseX = e.clientX; mouseY = e.clientY; isMouseOnStage = true; }).bind("mouseleave", function(e) { isMouseOnStage = false; }); reset(); function reset() { stageWidth = $("#wrapper").width(); stageHeight = $("#wrapper").height(); $("#wrapper canvas").attr("width", stageWidth); $("#wrapper canvas").attr("height", stageHeight); // 表示オブジェクトを作成 objectList = []; // 各Cellを作成 var x = prms.objectDistance * .5; var y; cellXCount = Math.floor(stageWidth / prms.objectDistance); cellYCount = Math.floor(stageHeight / prms.objectDistance); for (var xIndex = 0; xIndex < cellXCount; xIndex++) { y = prms.objectDistance * .5; for (var yIndex = 0; yIndex < cellYCount; yIndex++) { var xDistFromCenter = x - stageWidth * .5; var yDistFromCenter = y - stageHeight * .5; var distFromCenter = Math.sqrt(xDistFromCenter * xDistFromCenter) + Math.sqrt(yDistFromCenter * yDistFromCenter); var circleRotation = Math.PI * prms.animationDelta * distFromCenter; objectList.push( new Circle( x, y, circleRotation // _rotationV ) ); y += prms.objectDistance; } x += prms.objectDistance; } //各Cellの上下左右のCellをセット var tempCell; var tempIndex; for (xIndex = 0; xIndex < cellXCount; xIndex++) { for (yIndex = 0; yIndex < cellYCount; yIndex++) { tempIndex = xIndex * cellYCount + yIndex; tempCell = objectList[tempIndex]; //左のCellをセット if (xIndex > 0) { tempIndex = (xIndex - 1) * cellYCount + yIndex; tempCell.leftCircle = objectList[tempIndex]; } //右のCellをセット if (xIndex < cellXCount - 1) { tempIndex = (xIndex + 1) * cellYCount + yIndex; tempCell.rightCircle = objectList[tempIndex]; } //上のCellをセット if (yIndex > 0) { tempIndex = xIndex * cellYCount + yIndex - 1; tempCell.topCircle = objectList[tempIndex]; } //下のCellをセット if (yIndex < cellYCount - 1) { tempIndex = xIndex * cellYCount + yIndex + 1; tempCell.bottomCircle = objectList[tempIndex]; } } } // タイマ┼をリセット if (timeout) { clearTimeout(timeout); } timeout = setTimeout(onEnterFrame, 1000 / prms.fps); } function Circle(_x, _y, _rotation) { this.x = _x; this.y = _y; this.vx = 0; this.vy = 0; this.ax = 0; this.ay = 0; this.rotation = _rotation; this.cx = _x; this.cy = _y; this.rightCircle = null; this.leftCircle = null; this.topCircle = null; this.bottomCircle = null; } Circle.prototype.rotationV = prms.objectRotationV; Circle.prototype.radius = prms.objectRadius; Circle.prototype.tick = function() { this.rotation += this.rotationV; var _x = this.radius * Math.cos(this.rotation) + this.cx; var _y = this.radius * Math.sin(this.rotation) + this.cy; var springK = prms.animationSpringK; var friction = prms.animationFriction; var mouseF = prms.mouseForce; if (isMouseOnStage) { //マウス位置からの距滕反比例して加速 var distX = this.x - mouseX; var distY = this.y - mouseY; var dist = Math.sqrt(distX * distX + distY * distY); var rad = Math.atan2(distY, distX); this.ax = mouseF / dist * Math.cos(rad); this.ay = mouseF / dist * Math.sin(rad); } else { this.ax = 0; this.ay = 0; } this.ax += -(this.x - _x) * springK - friction * this.vx; this.ay += -(this.y - _y) * springK - friction * this.vy; this.vx += this.ax; this.vy += this.ay; this.x += this.vx; this.y += this.vy; if (this.x > this.cx + prms.objectDistance) { this.x = this.cx + prms.objectDistance; } else if (this.x < this.cx - prms.objectDistance) { this.x = this.cx - prms.objectDistance; } if (this.y > this.cy + prms.objectDistance) { this.y = this.cy + prms.objectDistance; } else if (this.y < this.cy - prms.objectDistance) { this.y = this.cy - prms.objectDistance; } } function onEnterFrame() { var len = objectList.length; var object; // 表示オブジェクトの位置を?算 while (len > 0) { len -= 1; object = objectList[len]; object.tick(); } // 表示オブジェクトを描画 context.clearRect(0, 0, stageWidth, stageHeight); var tempCell; context.strokeStyle = 'rgba(255,255,255,.12)'; for (var x = 0; x < cellXCount; x++) { for (var y = 0; y < cellYCount; y++) { idx = x * cellYCount + y; tempCell = objectList[idx]; if (tempCell.rightCircle && tempCell.bottomCircle) { context.beginPath(); var rCell = tempCell.rightCircle; var bCell = tempCell.bottomCircle; var rbCell = tempCell.rightCircle.bottomCircle; var width1 = rbCell.x - tempCell.x; var width2 = rCell.x - bCell.x; var height1 = rbCell.y - tempCell.y; var height2 = bCell.y - rCell.y; /* var vWidth1 = rbCell.vx - tempCell.vx; var vWidth2 = rCell.vx - bCell.vx; var vHeight1 = rbCell.vy - tempCell.vy; var vHeight2 = bCell.vy - rCell.vy; */ var hue = 160 + (tempCell.x + tempCell.y) / (stageWidth + stageHeight) * 50; var lightness = Math.log( Math.sqrt((width1 * height1 / (prms.objectDistance * prms.objectDistance) + width2 * height2 / (prms.objectDistance * prms.objectDistance)) / 2) ) * 8 + 10; var saturation = 100; context.fillStyle = 'hsl(' + hue + ',' + saturation + '%,' + lightness + '%)'; context.moveTo(tempCell.x, tempCell.y); context.lineTo(tempCell.rightCircle.x, tempCell.rightCircle.y); context.lineTo(tempCell.rightCircle.bottomCircle.x, tempCell.rightCircle.bottomCircle.y); context.lineTo(tempCell.bottomCircle.x, tempCell.bottomCircle.y); context.closePath(); context.stroke(); context.fill(); } } } // 次フレ┼ム呼び出し timeout = setTimeout(onEnterFrame, 1000 / prms.fps); } })
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>3d波纹动画-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号