jQuery 实现动态粒子特效,太美了!!!
啥也不说了,先上图
太美了,有没有!!
//html
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<div id="jsi-particle-container" class="container"></div>//css
html,body {width: 100%;height: 100%;margin: 0;padding: 0;overflow: hidden;
}
.container{width: 100%;height: 100%;margin: 0;padding: 0;background-color: #000000;
}//js
var RENDERER = {PARTICLE_COUNT : 1000,PARTICLE_RADIUS : 1,MAX_ROTATION_ANGLE : Math.PI / 60,TRANSLATION_COUNT : 500,init : function(strategy){this.setParameters(strategy);this.createParticles();this.setupFigure();this.reconstructMethod();this.bindEvent();this.drawFigure();},setParameters : function(strategy){this.$window = $(window);this.$container = $('#jsi-particle-container');this.width = this.$container.width();this.height = this.$container.height();this.$canvas = $('<canvas />').attr({width : this.width, height : this.height}).appendTo(this.$container);this.context = this.$canvas.get(0).getContext('2d');this.center = {x : this.width / 2, y : this.height / 2};this.rotationX = this.MAX_ROTATION_ANGLE;this.rotationY = this.MAX_ROTATION_ANGLE;this.strategyIndex = 0;this.translationCount = 0;this.theta = 0;this.strategies = strategy.getStrategies();this.particles = [];},createParticles : function(){for(var i = 0; i < this.PARTICLE_COUNT; i ++){this.particles.push(new PARTICLE(this.center));}},reconstructMethod : function(){this.setupFigure = this.setupFigure.bind(this);this.drawFigure = this.drawFigure.bind(this);this.changeAngle = this.changeAngle.bind(this);},bindEvent : function(){this.$container.on('click', this.setupFigure);this.$container.on('mousemove', this.changeAngle);},changeAngle : function(event){var offset = this.$container.offset(),x = event.clientX - offset.left + this.$window.scrollLeft(),y = event.clientY - offset.top + this.$window.scrollTop();this.rotationX = (this.center.y - y) / this.center.y * this.MAX_ROTATION_ANGLE;this.rotationY = (this.center.x - x) / this.center.x * this.MAX_ROTATION_ANGLE;},setupFigure : function(){for(var i = 0, length = this.particles.length; i < length; i++){this.particles[i].setAxis(this.strategies[this.strategyIndex]());}if(++this.strategyIndex == this.strategies.length){this.strategyIndex = 0;}this.translationCount = 0;},drawFigure : function(){requestAnimationFrame(this.drawFigure);this.context.fillStyle = 'rgba(0, 0, 0, 0.2)';this.context.fillRect(0, 0, this.width, this.height);for(var i = 0, length = this.particles.length; i < length; i++){var axis = this.particles[i].getAxis2D(this.theta);this.context.beginPath();this.context.fillStyle = axis.color;this.context.arc(axis.x, axis.y, this.PARTICLE_RADIUS, 0, Math.PI * 2, false);this.context.fill();}this.theta++;this.theta %= 360;for(var i = 0, length = this.particles.length; i < length; i++){this.particles[i].rotateX(this.rotationX);this.particles[i].rotateY(this.rotationY);}this.translationCount++;this.translationCount %= this.TRANSLATION_COUNT;if(this.translationCount == 0){this.setupFigure();}}
};
var STRATEGY = {SCATTER_RADIUS :150,CONE_ASPECT_RATIO : 1.5,RING_COUNT : 5,getStrategies : function(){var strategies = [];for(var i in this){if(this[i] == arguments.callee || typeof this[i] != 'function'){continue;}strategies.push(this[i].bind(this));}return strategies;},createSphere : function(){var cosTheta = Math.random() * 2 - 1,sinTheta = Math.sqrt(1 - cosTheta * cosTheta),phi = Math.random() * 2 * Math.PI;return {x : this.SCATTER_RADIUS * sinTheta * Math.cos(phi),y : this.SCATTER_RADIUS * sinTheta * Math.sin(phi),z : this.SCATTER_RADIUS * cosTheta,hue : Math.round(phi / Math.PI * 30)};},createTorus : function(){var theta = Math.random() * Math.PI * 2,x = this.SCATTER_RADIUS + this.SCATTER_RADIUS / 6 * Math.cos(theta),y = this.SCATTER_RADIUS / 6 * Math.sin(theta),phi = Math.random() * Math.PI * 2;return {x : x * Math.cos(phi),y : y,z : x * Math.sin(phi),hue : Math.round(phi / Math.PI * 30)};},createCone : function(){var status = Math.random() > 1 / 3,x,y,phi = Math.random() * Math.PI * 2,rate = Math.tan(30 / 180 * Math.PI) / this.CONE_ASPECT_RATIO;if(status){y = this.SCATTER_RADIUS * (1 - Math.random() * 2);x = (this.SCATTER_RADIUS - y) * rate;}else{y = -this.SCATTER_RADIUS;x = this.SCATTER_RADIUS * 2 * rate * Math.random();}return {x : x * Math.cos(phi),y : y,z : x * Math.sin(phi),hue : Math.round(phi / Math.PI * 30)};},createVase : function(){var theta = Math.random() * Math.PI,x = Math.abs(this.SCATTER_RADIUS * Math.cos(theta) / 2) + this.SCATTER_RADIUS / 8,y = this.SCATTER_RADIUS * Math.cos(theta) * 1.2,phi = Math.random() * Math.PI * 2;return {x : x * Math.cos(phi),y : y,z : x * Math.sin(phi),hue : Math.round(phi / Math.PI * 30)};}
};
var PARTICLE = function(center){this.center = center;this.init();
};
PARTICLE.prototype = {SPRING : 0.01,FRICTION : 0.9,FOCUS_POSITION : 300,COLOR : 'hsl(%hue, 100%, 70%)',init : function(){this.x = 0;this.y = 0;this.z = 0;this.vx = 0;this.vy = 0;this.vz = 0;this.color;},setAxis : function(axis){this.translating = true;this.nextX = axis.x;this.nextY = axis.y;this.nextZ = axis.z;this.hue = axis.hue;},rotateX : function(angle){var sin = Math.sin(angle),cos = Math.cos(angle),nextY = this.nextY * cos - this.nextZ * sin,nextZ = this.nextZ * cos + this.nextY * sin,y = this.y * cos - this.z * sin,z = this.z * cos + this.y * sin;this.nextY = nextY;this.nextZ = nextZ;this.y = y;this.z = z;},rotateY : function(angle){var sin = Math.sin(angle),cos = Math.cos(angle),nextX = this.nextX * cos - this.nextZ * sin,nextZ = this.nextZ * cos + this.nextX * sin,x = this.x * cos - this.z * sin,z = this.z * cos + this.x * sin;this.nextX = nextX;this.nextZ = nextZ;this.x = x;this.z = z;},rotateZ : function(angle){var sin = Math.sin(angle),cos = Math.cos(angle),nextX = this.nextX * cos - this.nextY * sin,nextY = this.nextY * cos + this.nextX * sin,x = this.x * cos - this.y * sin,y = this.y * cos + this.x * sin;this.nextX = nextX;this.nextY = nextY;this.x = x;this.y = y;},getAxis3D : function(){this.vx += (this.nextX - this.x) * this.SPRING;this.vy += (this.nextY - this.y) * this.SPRING;this.vz += (this.nextZ - this.z) * this.SPRING;this.vx *= this.FRICTION;this.vy *= this.FRICTION;this.vz *= this.FRICTION;this.x += this.vx;this.y += this.vy;this.z += this.vz;return {x : this.x, y : this.y, z : this.z};},getAxis2D : function(theta){var axis = this.getAxis3D(),scale = this.FOCUS_POSITION / (this.FOCUS_POSITION + axis.z);return {x : this.center.x + axis.x * scale, y : this.center.y - axis.y * scale, color : this.COLOR.replace('%hue', this.hue + theta)};}
};
$(function(){RENDERER.init(STRATEGY);
});
菜鸟教程 ---- jQuery教程
菜鸟教程,好棒的一个学习网站
jQuery 实现动态粒子特效,太美了!!!相关推荐
- html怎样实现动态背景效果,利用jQuery实现动态背景特效
特效描述:利用jQuery实现 动态背景特效.利用jQuery实现动态背景特效 代码结构 1. 引入CSS 2. 引入JS 3. HTML代码 Example 1 ooh, pretty. Notic ...
- python动态粒子素材,太魔性了,用 Python 实现火爆全网的「蚂蚁呀嘿」视频特效!...
大家好,我是安果! 最近在抖音上看到很多「蚂蚁呀嘿」的魔性视频,各方大佬齐齐上阵 刚好看到百度的开源项目,基于 PaddleGAN 实现表情迁移,于是也来玩一把! 先来看一下生成的效果图,各大编程创始 ...
- 前端使用particlesjs实现背景的动态粒子特效
废话不多说,先上效果图: 这种动态的背景特效看似十分复杂,但制作起来其实非常简单. 我们这里借助了一个特效库叫做particles.js particles.js库的话我们可以从github网站下载到 ...
- Vue动态粒子特效插件(背景线条吸附动画)
目录 效果图: 一.安装: 二.引入 main.js 文件: 三.使用: 四.属性说明: 效果图: 一.安装: npm install vue-particles --save 二.引入 main.j ...
- 一款jQuery立体感动态下拉导航菜单特效
一款jQuery立体感动态下拉导航菜单特效,鼠标经过,在菜单栏上方下拉出一个背景图片,效果十分不错的一款jquery特效. 对IE6都是兼容的,希望大家好好研究研究. 适用浏览器:IE6.IE7.IE ...
- java实现3D动态效果_js实现3D粒子酷炫动态旋转特效
js实现3D粒子酷炫动态旋转特效(效果比较酷炫,中途不仅有形态的变换,还有颜色的变化,希望大家能够喜欢) 代码实现过程中的静态截图 New Document html,body{ margin:0px ...
- jquery实现动态表格项目(表格增加删除/全选/表格变色特效等功能)(附源码+javaWEB开发如果需要可以直接使用)
jquery实现动态表格项目(表格增加删除/全选/表格变色特效)
- 三郎前端特效学习源代码:魔法旋转粒子动态渐变特效
三郎前端特效学习源代码:魔法旋转粒子动态渐变特效 简单介绍 效果图 源代码 html部分 js部分 第二个js部分 简单介绍 类似电影里的魔法效果 轨迹次数速度都可以自己改改 效果图 源代码 html ...
- Unity 动态改变整个粒子特效缩小放大
1.在粒子特效最上层添加 PSScale 这个脚本,面板上更改这个psScaleFloat,代码很简单我就不写注释了 2. 鼠标左键点一下更改粒子大小 using System.Collections ...
最新文章
- kubernetes 1.8 高可用安装(一)
- linux push path,Linux系统shell使用几点摘录(二)
- 18.28 getchar()函数与缓冲区问题
- 工作单元php,php – 无法从工作单元测试用例构建最简单的套件
- Visual Studio 2017 15.5预览版添加对F# Core及Standard的支持
- iphone 文件保存策略
- 【渝粤题库】国家开放大学2021春2094法理学题目
- 巧用RoboCopy工具
- 11年的macbook还能用吗_8年老本的第二春:2011款Macbook Pro换血记
- python之列表索引
- 二阶魔方万能还原公式_【二阶篇】一个万能公式还原二阶魔方
- android车载行业前景,车载 Android 系统快来了,但前景可能并不乐观
- GitHub 有哪些 macOS 开源软件?
- 精美UI界面欣赏[1]
- 广东省第三届职业技能大赛网络安全项目模块B
- [LeetCode]179.Largest Number
- 网络安全基本属性和STRIDE
- 第2天 C语言32个关键字
- 2023中央财经大学MTI英语翻译硕士专业考研成功经验分享
- flac格式怎么转换mp3?
热门文章
- electron-vue打包后样式变大以及不同分辨率屏幕适配问题
- 学习微博中情感分类的句子表达(NLPCC2013)
- negroni-gzip源代码分析
- docker 分析cpu占用过高
- [leetcode] 213. House Robber II 解题报告
- 机器学习之变分推断(三)基于平均场假设变分推断与广义EM
- 【Pytorch】计算矩阵中向量之间的两两相似性
- Android事件分发原理
- html5 语音唤醒,真正实现息屏语音唤醒小爱同学!释放你的双手,逼格满满哦!...
- 基于Vue+ElementUI的省市区地址选择通用组件