DDR爱好者之家 Design By 杰米
效果图
1.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); });
2.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; }
3.html部分
<script src="/UploadFiles/2021-04-02/jquery.min.js">以上就是jQuery 动态粒子效果示例代码的详细内容,更多关于jQuery 动态粒子效果的资料请关注其它相关文章!
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
2024年11月24日
2024年11月24日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]