最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery實現(xiàn)動態(tài)粒子效果

 更新時間:2021年03月18日 08:36:13   作者:云杰8了  
這篇文章主要為大家詳細介紹了jQuery實現(xiàn)動態(tài)粒子效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了jQuery實現(xiàn)動態(tài)粒子效果的具體代碼,供大家參考,具體內(nèi)容如下

效果圖

代碼

<!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>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:

相關(guān)文章

  • jquery插件制作 自增長輸入框?qū)崿F(xiàn)代碼

    jquery插件制作 自增長輸入框?qū)崿F(xiàn)代碼

    本章我們將創(chuàng)建一個自增長的輸入框插件,jquery.aotogrow.js
    2012-08-08
  • 談談對jquery ui tabs 的理解

    談談對jquery ui tabs 的理解

    本文給大家介紹jquery ui tabs的理解,包括屬性、事件、方法和技巧等相關(guān)知識,對jquery ui tabs感興趣的朋友一起學習吧
    2015-11-11
  • jQuery插件擴展操作入門示例

    jQuery插件擴展操作入門示例

    這篇文章主要介紹了jQuery插件擴展操作,結(jié)合簡單實例形式分析了jQuery擴展方法的定義與使用技巧,非常簡單易懂,需要的朋友可以參考下
    2017-01-01
  • 教你一步步用jQyery實現(xiàn)輪播器

    教你一步步用jQyery實現(xiàn)輪播器

    相信大家應該都會看到在各大網(wǎng)站上都有一個輪播器的效果,于是自己不禁也想做一個,查了資料,看了輪播器的原理,慢慢的試著做了做,最終效果勉勉強強,但還是想總結(jié)出來,或許對有需要的朋友們帶來一定的幫助,下面來一起看看吧。
    2016-12-12
  • jQuery實現(xiàn)的超酷蘋果風格圖標滑出菜單效果代碼

    jQuery實現(xiàn)的超酷蘋果風格圖標滑出菜單效果代碼

    這篇文章主要介紹了jQuery實現(xiàn)的超酷蘋果風格圖標滑出菜單效果代碼,涉及jQuery基于鼠標hover事件動態(tài)操作頁面元素屬性的相關(guān)技巧,非常美觀實用,需要的朋友可以參考下
    2015-09-09
  • jQuery分組選擇器用法實例

    jQuery分組選擇器用法實例

    這篇文章主要介紹了jQuery分組選擇器用法,以實例形式分析了分組選擇器的功能與具體用法技巧,具有一定的參考借鑒價值,需要的朋友可以參考下
    2014-12-12
  • 為jquery的ajaxfileupload增加附加參數(shù)的方法

    為jquery的ajaxfileupload增加附加參數(shù)的方法

    這篇文章主要介紹了為jquery的ajaxfileupload增加附加參數(shù)的方法,需要的朋友可以參考下
    2014-03-03
  • jQuery 性能優(yōu)化手冊 推薦

    jQuery 性能優(yōu)化手冊 推薦

    現(xiàn)在jquery應用的越來越多, 有些同學在享受爽快淋漓coding時就將性能問題忽略了,  比如我.  jquery雖在諸多的js類庫中性能表現(xiàn)還算優(yōu)秀, 但畢竟不是在用原生的javascript開發(fā), 性能問題還是需要引起重視的.
    2010-02-02
  • html、css和jquery相結(jié)合實現(xiàn)簡單的進度條效果實例代碼

    html、css和jquery相結(jié)合實現(xiàn)簡單的進度條效果實例代碼

    這篇文章主要介紹了html、css和jquery相結(jié)合實現(xiàn)簡單的進度條效果的實例代碼,這個進度條特別簡單,首先html里面的話就是一個div里面嵌套一個div,然后寫好想要的樣式就行了,具有一定的參考借鑒價值,感興趣的朋友一起看看吧
    2016-10-10
  • jQuery實現(xiàn)監(jiān)聽下拉框選中內(nèi)容發(fā)生改變操作示例

    jQuery實現(xiàn)監(jiān)聽下拉框選中內(nèi)容發(fā)生改變操作示例

    這篇文章主要介紹了jQuery實現(xiàn)監(jiān)聽下拉框選中內(nèi)容發(fā)生改變操作,結(jié)合實例形式分析了jQuery針對select選中觸發(fā)change事件相關(guān)操作技巧,需要的朋友可以參考下
    2018-07-07

最新評論

策勒县| 郑州市| 成武县| 开封县| 临西县| 朝阳区| 塘沽区| 饶阳县| 安达市| 霍林郭勒市| 普格县| 沾益县| 汨罗市| 清镇市| 电白县| 建平县| 高清| 岑巩县| 中西区| 鲁甸县| 安乡县| 宝清县| 天水市| 江阴市| 景洪市| 米林县| 渑池县| 平安县| 永德县| 深州市| 沙河市| 东明县| 黎平县| 平定县| 婺源县| 兴海县| 邵武市| 柞水县| 盐山县| 沭阳县| 息烽县|