广告
返回顶部
首页 > 资讯 > 精选 >使用jQuery怎么实现一个动态粒子效果
  • 465
分享到

使用jQuery怎么实现一个动态粒子效果

2023-06-14 05:06:07 465人浏览 泡泡鱼
摘要

使用Jquery怎么实现一个动态粒子效果?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。<!DOCTYPE html><html lan

使用Jquery怎么实现一个动态粒子效果?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

<!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怎么实现一个动态粒子效果问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注编程网精选频道了解更多相关知识。

--结束END--

本文标题: 使用jQuery怎么实现一个动态粒子效果

本文链接: https://www.lsjlt.com/news/268452.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 使用jQuery怎么实现一个动态粒子效果
    使用jQuery怎么实现一个动态粒子效果?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。<!DOCTYPE html><html lan...
    99+
    2023-06-14
  • jQuery实现动态粒子效果
    本文实例为大家分享了jQuery实现动态粒子效果的具体代码,供大家参考,具体内容如下 效果图 代码 <!DOCTYPE html> <html lang="...
    99+
    2022-11-11
  • 使用CSS3怎么实现一个粒子动画效果
    本篇文章给大家分享的是有关使用CSS3怎么实现一个粒子动画效果,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。按钮点击粒子动画<div class="b...
    99+
    2023-06-08
  • 使用canvas怎么实现一个粒子动效
    本篇文章为大家展示了使用canvas怎么实现一个粒子动效,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。绘制刻度此例为小时刻度的绘制:表盘上共有12个小时,Math.PI为180&deg;,每...
    99+
    2023-06-09
  • 使用Canvas怎么实现一个炫丽的粒子运动效果
    使用Canvas怎么实现一个炫丽的粒子运动效果?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。html 代码<!DOCTYPE html>&...
    99+
    2023-06-09
  • vue3中使用VueParticles实现粒子动态背景效果
    目录particles.vue3官网可以仔细看下这里 有案例跟文档官网 Demo好了直接进入主题 安装使用Vue3 语法糖中使用配置单独写到文件particles.js,代码看起来简...
    99+
    2022-11-13
  • CSS3中怎么实现粒子动画效果
    这期内容当中小编将会给大家带来有关CSS3中怎么实现粒子动画效果,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。按钮点击粒子动画<div class=&qu...
    99+
    2022-10-19
  • 使用canvas怎么实现一个粒子动画背景
    使用canvas怎么实现一个粒子动画背景?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。创建canvas首先需要在需要展示粒子背景的父元素中创建一个canvas标签, 指定wid...
    99+
    2023-06-09
  • 怎么使用JavaScript+Canvas实现带跳动效果的粒子动画
    这篇“怎么使用JavaScript+Canvas实现带跳动效果的粒子动画”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“怎么使...
    99+
    2023-07-05
  • 使用canvas怎么实现一个github404动态效果
    使用canvas怎么实现一个github404动态效果?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。文件目录文件资源文件源码与图片在文章末尾给出代码网页的body部分这里给...
    99+
    2023-06-09
  • 怎么在JavaScript中使用canvas实现一个随机粒子特效
    本篇文章给大家分享的是有关怎么在JavaScript中使用canvas实现一个随机粒子特效,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。Java的特点有哪些Java的特点有哪些...
    99+
    2023-06-14
  • 怎么使用jQuery的api实现动态效果
    本篇内容主要讲解“怎么使用jQuery的api实现动态效果”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么使用jQuery的api实现动态效果”吧!为什么要学...
    99+
    2022-10-19
  • 使用jQuery怎么实现一个手风琴效果
    本篇文章为大家展示了使用jQuery怎么实现一个手风琴效果,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。运用jQuery,动画样式进行轮播图切换前提,需要引入animate.css(官网下载就有)H...
    99+
    2023-06-14
  • 使用jQuery怎么实现一个弹出层效果
    使用jQuery怎么实现一个弹出层效果,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。1 //------------------...
    99+
    2022-10-19
  • 怎么在jquery中使用fadeIn()实现一个淡入动画效果
    这篇文章给大家介绍怎么在jquery中使用fadeIn()实现一个淡入动画效果,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。jquery是什么jquery是一个简洁而快速的JavaScript库,它具有独特的链式语法和...
    99+
    2023-06-14
  • 怎么在Html5中使用canvas实现一个粒子时钟
    这篇文章将为大家详细讲解有关怎么在Html5中使用canvas实现一个粒子时钟,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。首先要创建一个html文件并添加一个canvas画布,如下:<...
    99+
    2023-06-09
  • 使用css3怎么实现一个背景动态渐变效果
    使用css3怎么实现一个背景动态渐变效果?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。css是什么意思css是一种用来表现HTML或XML等文件样式的计算机语言,主要是用来设计...
    99+
    2023-06-08
  • 怎么使用jQuery实现一个图片不停旋转动画效果
    这篇文章主要介绍“怎么使用jQuery实现一个图片不停旋转动画效果”,在日常操作中,相信很多人在怎么使用jQuery实现一个图片不停旋转动画效果问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么使用jQuer...
    99+
    2023-07-05
  • Android应用怎么实现一个浮动状态栏效果
    这期内容当中小编将会给大家带来有关Android应用怎么实现一个浮动状态栏效果,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。首先:要实现的是浮动状态栏效果,通过在Activity的onCreate方法中调...
    99+
    2023-05-31
    android roi
  • jQuery插件分享:Turn.js实现一个移动端电子书翻页效果
    怎么实现一个炫酷的翻书效果?下面本篇文章给大家分享一个jQuery插件--Turn.js,介绍一下怎么用Turn.js 实现移动端电子书翻页项目,希望对大家有所帮助!先来看一下效果:关于Turn.js它是一个轻量级的 (15kb) jQue...
    99+
    2023-05-14
    jquery turn.js
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作