版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第jQuery实现动态粒子效果本文实例为大家分享了jQuery实现动态粒子效果的具体代码,供大家参考,具体内容如下
效果图
代码
!DOCTYPEhtml
htmllang="en"
head
metacharset="UTF-8"
metahttp-equiv="X-UA-Compatible"content="IE=edge"
metaname="viewport"content="width=device-width,initial-scale=1.0"
titleDocument/title
scriptsrc="/jquery/1.10.2/jquery.min.js"/script
divid="jsi-particle-container"/div
style
html,
body{
width:100%;
height:100%;
margin:0;
padding:0;
overflow:hidden;
.container{
width:100%;
height:100%;
margin:0;
padding:0;
background-color:#000000;
/style
/head
body
script
varRENDERER={
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(vari=0;ithis.PARTICLE_COUNT;i++){
this.particles.push(newPARTICLE(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){
varoffset=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(vari=0,length=this.particles.length;ilength;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(vari=0,length=this.particles.length;ilength;i++){
varaxis=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(vari=0,length=this.particles.length;ilength;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();
varSTRATEGY={
SCATTER_RADIUS:150,
CONE_ASPECT_RATIO:1.5,
RING_COUNT:5,
getStrategies:function(){
varstrategies=[];
for(variinthis){
if(this[i]==arguments.callee||typeofthis[i]!='function'){
continue;
strategies.push(this[i].bind(this));
returnstrategies;
createSphere:function(){
varcosTheta=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(){
vartheta=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(){
varstatus=Math.random()1/3,
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(){
vartheta=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)
varPARTICLE=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){
varsin=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){
varsin=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){
varsin=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;
getAx
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 贵州省毕节地区金沙县2025-2026学年普通高中毕业班摸底考试英语试题(一模66C)含解析
- 湖北省黄石市阳新一中卓越联盟重点名校2026届初三下学期第一次检测试题考试英语试题试卷含解析
- 四川省成都外国语校2026年第五次月考初三物理试题含解析
- 辽宁省丹东第十中学2026年初三元月调考英语试题含解析
- 浙江省永康市龙川校2026年初三下学期期中试卷物理试题含解析
- 内蒙古自治区通辽市奈曼旗达标名校2025-2026学年初三英语试题4月质量调研测试(二模)试题含解析
- 湖南省新化县上梅中学2025-2026学年初三一轮复习周测(一)语文试题试卷含解析
- 浙江省温州市文成县黄坦中学2026年初三开学摸底联考语文试题试卷含解析
- 无锡市滨湖区重点达标名校2025-2026学年初三下学期统一调研测试(二)语文试题含解析
- 阶梯式康复护理方案在一例重症肺炎拔管困难患者护理中的应用
- 周杰伦课件介绍
- 公司管理层离职管理制度
- 2025年重庆市中考数学试卷真题及答案详解(精校打印版)
- (高清版)DG∕TJ 08-110-2021 餐饮单位清洁设计技术标准
- 年产200吨高纯金属铯铷项目报告书
- 煤矿各级各岗位人员职业病防治责任制
- 2025新人教版七年级下册英语 Unit 2知识点梳理及语法讲义(答案版)
- (新版)多旋翼无人机超视距驾驶员执照参考试题(附答案)
- 2025年包钢(集团)公司招聘笔试参考题库含答案解析
- 【公开课】多姿与多彩(生活色彩)课件高中美术人教版+(2019)+选择性必修1+绘画
- 《植物生产与环境》考试复习题及答案
评论
0/150
提交评论