Particle Js not working on my ruby on rails project

452 Views Asked by At

I am trying to implement the particles effect on my ruby on rails project but after following some tutorials and the github instruction of the particles package available I am not getting the effect on my local server even when I am specifying a grey background. Maybe you can suggest which one is my error or what I am missing. Here is my code.

Application.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 .

Application.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
*/

back.css

#particles-js{
    backgorund: #444;
} 

home.html.erb

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

I am not putting the lines

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

because I think they are not required since I am using //= require_tree but I also tried putting them and it does not show anything.

back.css was only created in order to set the color of the backgorund of the particles effect and I am not posting the content of particles.js and app.js because I did not change anything of those files, they are the same ones that you can download from github.

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

Here is what I get:

Result

1

There are 1 best solutions below

0
jportella On BEST ANSWER

I solved it what I did is modify the app.js file as follows:

$(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"
   }
  }
 );
});

So as I am working in the console level I must change the name of the app.js file by the main.js as I am working directly in java language.Apart from that I remove the particles.js file and I used the particles.min.js file in the vendor folder and as a result I had to use //= require particles.min in the application.js file. If you know any other way to make it work or you can explain it in a better way or add some details to my answer you are welcome.