效果图


代码

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script><div id="jsi-particle-container" class="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>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);});</script>
</body></html>

jQuery动态粒子效果相关推荐

  1. 【CSON原创】HTML5字体动态粒子效果发布

    功能说明: 输入字体,按确定后,右侧画布出现字体的动态粒子效果. 效果预览: 输入显示内容: 实现分析: 之前看过hongru的事情没有想象中那么难--JX官网首页3D粒子效果,和当耐特砖家的HTML ...

  2. html粒子效果原理,HTML5字体动态粒子效果

    功能说明: 输入字体,按确定后,右侧画布出现字体的动态粒子效果. 效果预览: 详见:http://www.cnblogs.com/Cson/archive/2012/04/02/2429734.htm ...

  3. jQuery网页粒子效果背景插件

    下载地址 jQuery实现的背景粒子效果插件 ,可选的控制鼠标视差效果在桌面设备和移动设备上,工作在任何浏览器支持HTML5画布. dd:

  4. Canvas实现HTML动态粒子效果背景

    之前参考诸多博客,发现许多博主自定义的博客主页都会有很多动态的小粒子在页面漂浮,鼠标经过还会有响应事件,在这里,将代码记录一下. 首先,在html页面要先定义一个canvas元素: <canva ...

  5. Vue:项目使用vue-particles实现动态粒子效果作为背景显示

    实现过程 1. 安装vue-particles npm install vue-particles --save-dev 2. 全局配置vue-particles // 引入动态背景vue-parti ...

  6. leaflet实现风场动态粒子效果

    文章目录 前言 一.部分代码摘录 (一)velocity插件代码.js (二)插件使用示例代码 二.leaflet-velocity数据源格式 三.总结 前言 效果实现需要用到一款开源插件:leafl ...

  7. html5在线制作 知乎,html5canvas: 教你实现知乎登录动态粒子背景

    首先上效果图:最终效果图 因为使用gif图片的原因,线条不是很清晰,大家可以到我的博客观看效果:cherryblog.site/ ,(手机也有效果的哦) 或者直接在github上下载项目源码:gith ...

  8. jQuery制作动态酷效果总结

    jQuery是一个优秀的JavaScript框架,可以很好的解决不同浏览器兼容的问题,尤其是在ASP.NET MVC下,它的作用更加的凸显. jQuery在制作动态酷效果的时候有很强的优势,以下是笔者 ...

  9. html+js+css 调用jquery 工人信息管理功能(增删改查)前端实现,以及调用实现鼠标拖尾粒子效果的js库

    html + js + css 调用jquery以及underscore.min.js(配合代码实现鼠标粒子效果)实现全前端信息管理基本功能(增删改查) 先附上我运行的一段视频,手机打开清晰一点或者直 ...

最新文章

  1. Numpy、TensorFlow和Keras函数输入参数axis理解
  2. Activity采用栈式管理的理解
  3. junit 测试遇上java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing 错误
  4. 忘记密码漏洞案例分析
  5. PHP中过滤数组中的元素
  6. DDMMSS.SS转为DD
  7. A Simple Note on P4FPGA: A Rapid Prototyping Framework for P4
  8. 英文字典。怎样设计数据结构
  9. checked exception和unchecked exception区别
  10. JavaScript遇到浏览器不兼容与解决方案
  11. Spring, MyBatis 多数据源的配置和管理
  12. 网页上做笔记--Diigo
  13. 滴滴打车2015-2016
  14. 鼠标悬浮显示禁止图标
  15. Python安装火狐浏览器驱动
  16. 解决:Mac “微信”意外退出
  17. 免费的可直接运行的简单易懂的C++学生信息管理系统
  18. springboot默认日志log,控制台不打印mybatis sql执行日志解决办法
  19. pytorch矩阵运算
  20. 计算机组成与嵌入式系统 百度云,计算机组成及嵌入式系统.pdf

热门文章

  1. 我在 ClojureScript 的 2017
  2. 【数理知识】欧拉复数公式
  3. JAVA使用Tabula解析PDF表格
  4. excel报表技巧:几个关于汇报演示方面的小功能
  5. 清华姚班计算机专业,清华姚班聚集了中国计算机最顶尖的人才,毕业生都去哪儿了?...
  6. dotnet core 命令详解
  7. Java泛型之PECS原则
  8. Minio分布式存储系统
  9. 【前端基础】简单介绍什么是软件
  10. 双目视觉下空间坐标计算matlab,双目视觉下空间坐标计算 opencv+ 个人理解