参考网址:https://codepen.io/natewiley/pen/GJVOVw?depth=everything&order=popularity&page=2&q=Particle+Animation&show_forks=false
使用了 TweenMax 动画库

源码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Document</title>
  6. <style>
  7. html, body { height: 100%; } body { background: black; overflow: hidden; } .wrap { height: 100%;perspective: 200px; transform-style: preserve-3d; } .c { position: absolute; }
  8. </style>
  9. </head>
  10. <body>
  11. <div class="wrap">
  12. </div>
  13. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
  14. <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.17.0/TweenMax.min.js"></script>
  15. <script>
  16. //源码链接 https://codepen.io/anon/pen/goBRxj?depth=everything&order=popularity&page=2&q=Particle+Animation&show_forks=false
  17. //js https://cdnjs.cloudflare.com/ajax/libs/gsap/1.17.0/TweenMax.min.js
  18. var $wrap = $(".wrap"),
  19. w = $wrap.width(),
  20. h = $wrap.height();
  21. //添加 div
  22. for (var i = 0;i < 30;i++) {
  23. $("<div class=\"c\"></div>").appendTo($wrap);
  24. // console.log($(".wrap").find('div').length);
  25. }
  26. // console.log($(".wrap"));
  27. function random(min, max) {
  28. return (Math.random() * (max - min)) + min;
  29. }
  30. $wrap.find(".c").each(function(i) {
  31. var x = random(0, w),
  32. y = random(0, h),
  33. z = random(-1000, -200),
  34. color = "#fff";
  35. size = random(1, 6),
  36. c = $(this);
  37. c.css({
  38. background: color,
  39. height: size,
  40. width: size,
  41. borderRadius: "50%",
  42. boxShadow: "0 0 " + size + "px " + color
  43. })
  44. //dom 速度 {初始时的样式} {结束时的样式}
  45. TweenMax.fromTo(c, 10, {
  46. opacity: 0,
  47. x: x,
  48. y: y,
  49. z: z
  50. }, {
  51. opacity: 1,
  52. z: 200,
  53. repeat: -1,//是否重复执行
  54. // delay: i * -.015
  55. delay: i * -.3//延迟时间
  56. });
  57. });
  58. // function touches(e){
  59. // var x = e.touches ? e.touches[0].clientX : e.clientX,
  60. // y = e.touches ? e.touches[0].clientY : e.clientY;
  61. // TweenMax.to($wrap, 1, {
  62. // webkitPerspectiveOrigin: x + "px " + y +"px",
  63. // perspectiveOrigin: x + "px " + y +"px"
  64. // });
  65. // }
  66. // window.addEventListener("mousemove", touches);
  67. // window.addEventListener("touchstart", touches);
  68. // window.addEventListener("touchmove", touches);
  69. </script>
  70. </body>
  71. </html>

效果图

15.gif

具体的在公司页面上的实现

  1. PC 端

公司实现页面 PC 端 => 顶部 banner 效果

  • 源码 ``` banTopAnimate(); //顶部 ban 粒子效果 function banTopAnimate() {

    1. var $con = $("#ban__animate"),
    2. w = $con.width(),
    3. h = $con.height();
    4. //添加 div
    5. for (var i = 0; i < 50; i++) {
    6. $("<div class=\"animate__list\"></div>").appendTo($con);
    7. // console.log($(".wrap").find('div').length);
    8. }
    9. // console.log($(".wrap"));
    10. function random(min, max) {
    11. return (Math.random() * (max - min)) + min;
    12. }
    13. $con.find(".animate__list").each(function (i) {
    14. var x = random(0, w),
    15. y = random(0, h),
    16. z = random(-1000, -200),
    17. color = "#fff";
    18. size = random(1, 10),
    19. c = $(this);
    20. c.css({
    21. background: color,
    22. height: size,
    23. width: size,
    24. borderRadius: "50%",
    25. boxShadow: "0 0 " + size + "px " + color
    26. })
    27. //dom 速度 {初始时的样式} {结束时的样式}
    28. TweenMax.fromTo(c, 10, {
    29. opacity: 0,
    30. x: x,
    31. y: y,
    32. z: z
    33. }, {
    34. opacity: 1,
    35. z: 200,
    36. repeat: -1,//是否重复执行
    37. // delay: i * -.015
    38. delay: i * -.3//延迟时间
    39. });
    40. });

    }

  1. - 效果图
  2. > ![26.gif](http://upload-images.jianshu.io/upload_images/9064013-9fdc90329bf1d520.gif?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
  3. 2. 手机端
  4. > [公司实现页面 手机端](https://m.hizyd.com/Reports/Report2017Total) => 顶部 banner 效果
  5. - 源码

//顶部 .main1 动画 this.mainTopAnimate = function () { var _me = this; var $con = $(“#bananimate”), w = $con.width(), h = $con.height(); //添加 div for (var i = 0; i < 50; i++) { $(“<div class=\”animatelist\”>“).appendTo($con); // console.log($(“.wrap”).find(‘div’).length); } // console.log($(“.wrap”)); function random(min, max) { return (Math.random() * (max - min)) + min; }

  1. $con.find(".animate__list").each(function (i) {
  2. var x = random(0, w),
  3. y = random(0, h),
  4. z = random(-1000, -200),
  5. color = "#fff";
  6. size = random(1, 4),
  7. c = $(this);
  8. c.css({
  9. background: color,
  10. height: size,
  11. width: size,
  12. borderRadius: "50%",
  13. boxShadow: "0 0 " + size + "px " + color
  14. })
  15. //dom 速度 {初始时的样式} {结束时的样式}
  16. TweenMax.fromTo(c, 10, {
  17. opacity: 0,
  18. x: x,
  19. y: y,
  20. z: z
  21. }, {
  22. opacity: 1,
  23. z: 200,
  24. repeat: -1,//是否重复执行
  25. // delay: i * -.015
  26. delay: i * -.3//延迟时间
  27. });
  28. });
  29. return _me;
  30. };

```

  • 效果图

22.gif