<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>流体加载动画特效</title>
<style>
body {
background: #111;
overflow: hidden;
}
canvas {
bottom: 0;
left: 0;
margin: auto;
position: absolute;
right: 0;
top: 0;
}
</style>
</head>
<body>
<div></div>
<script>
var $ = {};
$.Particle = function( opt ) {
this.radius = 7;
this.x = opt.x;
this.y = opt.y;
this.angle = opt.angle;
this.speed = opt.speed;
this.accel = opt.accel;
this.decay = 0.01;
this.life = 1;
};
$.Particle.prototype.step = function( i ) {
this.speed += this.accel;
this.x += Math.cos( this.angle ) * this.speed;
this.y += Math.sin( this.angle ) * this.speed;
this.angle += $.PI / 64;
this.accel *= 1.01;
this.life -= this.decay;
if( this.life <= 0 ) {
$.particles.splice( i, 1 );
}
};
$.Particle.prototype.draw = function( i ) {
$.ctx.fillStyle = $.ctx.strokeStyle = 'hsla(' + ( $.tick + ( this.life * 120 ) ) + ', 100%, 60%, ' + this.life + ')';
$.ctx.beginPath();
if( $.particles[ i - 1 ] ) {
$.ctx.moveTo( this.x, this.y );
$.ctx.lineTo( $.particles[ i - 1 ].x, $.particles[ i - 1 ].y );
}
$.ctx.stroke();
$.ctx.beginPath();
$.ctx.arc( this.x, this.y, Math.max( 0.001, this.life * this.radius ), 0, $.TWO_PI );
$.ctx.fill();
var size = Math.random() * 1.25;
$.ctx.fillRect( ~~( this.x + ( ( Math.random() - 0.5 ) * 35 ) * this.life ), ~~( this.y + ( ( Math.random() - 0.5 ) * 35 ) * this.life ), size, size );
}
$.step = function() {
$.particles.push( new $.Particle({
x: $.width / 2 + Math.cos( $.tick / 20 ) * $.min / 2,
y: $.height / 2 + Math.sin( $.tick / 20 ) * $.min / 2,
angle: $.globalRotation + $.globalAngle,
speed: 0,
accel: 0.01
}));
$.particles.forEach( function( elem, index ) {
elem.step( index );
});
$.globalRotation += $.PI / 6;
$.globalAngle += $.PI / 6;
};
$.draw = function() {
$.ctx.clearRect( 0, 0, $.width, $.height );
$.particles.forEach( function( elem, index ) {
elem.draw( index );
});
};
$.init = function() {
$.canvas = document.createElement( 'canvas' );
$.ctx = $.canvas.getContext( '2d' );
$.width = 300;
$.height = 300;
$.canvas.width = $.width * window.devicePixelRatio;
$.canvas.height = $.height * window.devicePixelRatio;
$.canvas.style.width = $.width + 'px';
$.canvas.style.height = $.height + 'px';
$.ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
$.min = $.width * 0.5;
$.particles = [];
$.globalAngle = 0;
$.globalRotation = 0;
$.tick = 0;
$.PI = Math.PI;
$.TWO_PI = $.PI * 2;
$.ctx.globalCompositeOperation = 'lighter';
document.body.appendChild( $.canvas );
$.loop();
};
$.loop = function() {
requestAnimationFrame( $.loop );
$.step();
$.draw();
$.tick++;
};
$.init();
</script>
</body>
</html>
js流体加载动画特效.zip_js_加载_动画_流体_绘制流体动画
版权申诉
6 浏览量
2022-09-23
21:05:29
上传
评论
收藏 1KB ZIP 举报
局外狗
- 粉丝: 64
- 资源: 1万+
最新资源
- 自适应调节Q和R的自适应UKF(AUKF-QR)的MATLAB程序
- GROTESQUE靶场复现
- python数据分析实验一评估8 -12年级英语语言学习者(ELLS)的语言能力.zip
- 《Python短视频封面批量处理:ffmpeg与Pillow实战教程》, 知识领域:Python编程, 技术关键词:Python
- C语言《基于指纹识别和指静脉识别技术的嵌入式门禁系统,DSP硬件平台》+源代码+文档说明
- [33.0]iInhuman.apk
- 基于Qt开发的小工具包
- 学生课程实验学生模拟选课系统实验二学生模拟选课系统.zip
- 嵌入式linux软件开发、嵌入式linux驱动开发、c语言、单片机开发、IOT开发等面试要点记录
- 基于SpringBoot简洁优雅的个人博客系统 (3).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈