0

我正在尝试在我的 ruby​​ on rails 项目上实现粒子效果,但是在遵循了一些教程和可用的粒子包的 github 指令之后,即使我指定了灰色背景,我也没有在我的本地服务器上获得效果。也许您可以建议哪一个是我的错误或我缺少什么。这是我的代码。

应用程序.js

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts,    vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require particles.js
//= require app.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

应用程序.css

/*
* This is a manifest file that'll be compiled into application.css, which   will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/

返回.css

#particles-js{
    backgorund: #444;
} 

主页.html.erb

<h1>Rubsol#home</h1>
<p>Find me in app/views/rubsol/home.html.erb</p>
<div id="particles-js"></div>

我没有放线

<script src="particles.js"></script>
<script src="particles.js"></script>

因为我认为它们不是必需的,因为我使用的是 //= require_tree 但我也尝试过放置它们并且它没有显示任何内容。

back.css 只是为了设置粒子效果背景的颜色而创建的,我没有发布particle.js 和 app.js 的内容,因为我没有更改这些文件中的任何内容,它们是相同的你可以从github下载。

https://github.com/VincentGarreau/particles.js/

这是我得到的:

结果

4

1 回答 1

0

我解决了我所做的就是修改 app.js 文件如下:

$(document).ready(function(){

console.log("Loading particles.js");

particlesJS('particles-js',
 {
  "particles": {
    "number": {
      "value": 80,
      "density": {
        "enable": true,
        "value_area": 800
      }
    },
    "color": {
      "value": "#ffffff"
    },
    "shape": {
      "type": "circle",
      "stroke": {
        "width": 0,
        "color": "#000000"
      },
      "polygon": {
        "nb_sides": 5
      },
      "image": {
        "src": "img/github.svg",
        "width": 100,
        "height": 100
      }
    },
    "opacity": {
      "value": 0.5,
      "random": false,
      "anim": {
        "enable": false,
        "speed": 1,
        "opacity_min": 0.1,
        "sync": false
      }
    },
    "size": {
      "value": 5,
      "random": true,
      "anim": {
        "enable": false,
        "speed": 40,
        "size_min": 0.1,
        "sync": false
      }
    },
    "line_linked": {
      "enable": true,
      "distance": 150,
      "color": "#ffffff",
      "opacity": 0.4,
      "width": 1
    },
    "move": {
      "enable": true,
      "speed": 6,
      "direction": "none",
      "random": false,
      "straight": false,
      "out_mode": "out",
      "attract": {
        "enable": false,
        "rotateX": 600,
        "rotateY": 1200
      }
    }
  },
  "interactivity": {
    "detect_on": "canvas",
    "events": {
      "onhover": {
        "enable": true,
        "mode": "repulse"
      },
      "onclick": {
        "enable": true,
        "mode": "push"
      },
      "resize": true
    },
    "modes": {
      "grab": {
        "distance": 400,
        "line_linked": {
          "opacity": 1
        }
      },
      "bubble": {
        "distance": 400,
        "size": 40,
        "duration": 2,
        "opacity": 8,
        "speed": 3
      },
      "repulse": {
        "distance": 200
      },
      "push": {
        "particles_nb": 4
      },
      "remove": {
        "particles_nb": 2
      }
    }
  },
  "retina_detect": true,
  "config_demo": {
    "hide_card": false,
    "background_color": "#b61924",
    "background_image": "",
    "background_position": "50% 50%",
    "background_repeat": "no-repeat",
    "background_size": "cover"
   }
  }
 );
});

因此,当我在控制台级别工作时,我必须通过 main.js 更改 app.js 文件的名称,因为我直接使用 java 语言工作。除此之外,我删除了particles.js 文件并使用了粒子。供应商文件夹中的 min.js 文件,因此我必须在 application.js 文件中使用 //= requireparticles.min 。如果您知道使其工作的任何其他方式,或者您可以以更好的方式解释它或在我的回答中添加一些细节,欢迎您。

于 2017-01-05T23:49:46.040 回答