Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
JavaScript
/* click to clear and change hue don't look at or judge this code I just kept tweaking values and adding random things in a messy way it's full of magic numbers */ var c, ctx, w, h, cx, cy, branches, startHue, tick; function rand( min, max ) { return Math.random() * ( max - min ) + min; } function randInt( min, max ) { return Math.floor( min + Math.random() * ( max - min + 1 ) ); }; function Branch( hue, x, y, angle, vel ) { var move = 15; this.x = x + rand( -move, move ); this.y = y + rand( -move, move ); this.points = []; this.angle = angle != undefined ? angle : rand( 0, Math.PI * 1 ); this.vel = vel != undefined ? vel : rand( -4, 4 ); this.spread = 0; this.tick = 0; this.hue = hue != undefined ? hue : 200; this.life = 1; this.decay = 0.0015; this.dead = false; this.points.push({ x: this.x, y: this.y }); } Branch.prototype.step = function( i ) { this.life -= this.decay; if( this.life <= 0 ) { this.dead = true; } if( !this.dead ) { var lastPoint = this.points[ this.points.length - 1 ]; this.points.push({ x: lastPoint.x + Math.cos( this.angle ) * this.vel, y: lastPoint.y + Math.sin( this.angle ) * this.vel }); this.angle += rand( -this.spread, this.spread ); this.vel *= 0.99; this.spread = this.vel * 0.04; this.tick++; this.hue += 0.3; } else { branches.splice( i, 1 ); } }; Branch.prototype.draw = function() { if( !this.points.length || this.dead ) { return false; } var length = this.points.length, i = length - 1, point = this.points[ i ], lastPoint = this.points[ i - randInt( 5, 100 ) ]; //jitter = 8; if( lastPoint ) { var jitter = 2 + this.life * 6; ctx.beginPath(); ctx.moveTo( lastPoint.x, lastPoint.y ); ctx.lineTo( point.x + rand( -jitter, jitter ), point.y + rand( -jitter, jitter ) ); ctx.lineWidth = 1; var alpha = this.life * 0.075; ctx.strokeStyle = 'hsla(' + ( this.hue + rand( -10, 10 ) ) + ', 70%, 40%, ' + alpha + ')'; ctx.stroke(); } } function init() { c = document.getElementById( 'c' ); ctx = c.getContext( '2d' ); startHue = 220; branches = []; reset(); loop(); } function reset() { w = window.innerWidth; h = window.innerHeight; cx = w / 2; cy = h / 2; branches.length = 0; c.width = w; c.height = h; tick = 0; for( var i = 0; i < 500; i++ ) { branches.push( new Branch( startHue, cx, cy) ); } } function step() { var i = branches.length; while( i-- ) { branches[ i ].step( i ) } tick++; } function draw() { var i = branches.length; if( tick < 450 ) { ctx.save(); ctx.globalCompositeOperation = 'lighter'; ctx.globalAlpha = 0.002; ctx.translate( cx, cy ); var scale = 1 + tick * 0.00025 ; ctx.scale( scale, scale ); ctx.translate( -cx, -cy ); ctx.drawImage( c, rand( -150, 150 ), rand( -150, 150 ) ); ctx.restore(); } ctx.globalCompositeOperation = 'lighter'; while( i-- ) { branches[ i ].draw() } } function loop() { requestAnimationFrame( loop ); step(); draw(); step(); draw(); } window.addEventListener( 'resize', reset ); window.addEventListener( 'click', function() { startHue += 60; reset(); }); init();
粒子
时间
文字
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号