Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

particles.js not covering entire page

I'm trying to use particles.js as background, but I am not able to set the canvas as a full-size background.

I tried at least 10 different solution from similar issues but nothing worked. The canvas always results as as an element having width-height ratio as the screen but it doesn't cover it as a whole when it is resized. In addiction, it won't set as background but as a child of the body, over or below the remaining elements.

I simplified the code as much as possible and the problem still persist.

Example of the problem

HTML

<!DOCTYPE HTML>

<html>
    <head>
        <title>Try</title>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <link rel="stylesheet" media="screen" href="css/style.css">
    </head>

    <body>
        <div id="particles-js"></div>
        <div>
            <p>Something here</p>
        </div>
    </body>

    <script src="assets/js/particles.js"></script>
    <script src="assets/js/app.js"></script>
</html>

CSS

canvas{
  display:block;
  vertical-align:bottom;
  position: absolute;
}

/* ---- particles.js container ---- */

#particles-js{
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: #b61924;
  background-image: url('');
  background-size: cover;
  background-position: 50% 50%;
  background-repeat: no-repeat;
  top: 0;
}

APP.JS and PARTICLES.JS can be downloaded from the owner's website posted before. I'm using themas they are at the moment

Thanks for any help

like image 705
Nicola Zaltron Avatar asked Jul 30 '17 22:07

Nicola Zaltron


2 Answers

Ok I finally solved the background question: That's how I managed it (I'm pretty sure I had already tried that but re-building the whole html if finally worked)

CSS

#particles-js{
  width: 100%;
  height: 100%;
  position: fixed;
  background-color: #000;
  background-image: url('');
  background-size: cover;
  background-position: 50% 50%;
  background-repeat: no-repeat;
}

.body-particles{
  position: absolute;
  top: 0;
  left: 0;
  z-index: 100;
}

HTML

<html>
    <head>
        <title>Title</title>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />

        <!-- SOME CSSs HERE -->

        <link rel="stylesheet" media="screen" href="assets/css/particles.css">

         <!-- SOME SCRIPTS HERE -->
    </head>
    <body>
        <div class="body-particles">

        <!-- Wrapper -->
            <div id="wrapper">
                <!-- MY STUFF HERE, STYLED WITH MY CSS -->
            </div>
        </div>

        <!-- particles.js container -->
        <div id="particles-js"></div>

        <!-- scripts -->
        <script src="assets/js/particles.js"></script>
        <script src="assets/js/app.js"></script>

    </body>
</html>

Now, I have a new problem: being set as an underlying layer, it catch no pointer-events. As soon as I will make it works, I'll update the answer.

Obviously, feel free to help if you have any suggestion.

UPDATE: Workaround for mouseEvents: Adding class mouseEvents to elements I need to focus (for example , navbar, etc.)

CSS

.body-particles{
  pointer-events: none;
}

.mouseEvents{
  pointer-events: all;
}

However, it would be nice if someone knows a better way to keep events both in front and back layer

like image 81
Nicola Zaltron Avatar answered Nov 06 '22 12:11

Nicola Zaltron


I only had to do this...

HTML:

<body>
    <div id="particles-js"></div>
    ...
</body>

CSS:

#particles-js {
  height: 100%;
  width: 100%;
  position: fixed;
  z-index: -100;
}
like image 5
ypicard Avatar answered Nov 06 '22 14:11

ypicard