In this code I have two div elements saved, and each of them is set on the entire length of the page (100vh), but instead of being one above the other, as if I wanted to overlap. Part of the problem is solved instead of "absolute" in particles-js I put "static" then they do not overlap each other, but animated particles are imposed on div with Content
HTML
<div id="particles-js">
</div>
<div class="content">
<h1>Content</h1>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/particles.js/2.0.0/particles.min.js"></script>
CSS
#particles-js {
position: absolute;
width: 100%;
height: 100vh;
z-index: -1;
background-color: #222;
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
}
canvas{
position: absolute;
width: 100%;
height: 500px;
z-index: -1;
}
.content
{
position: relative;
height: 100vh;
background-color: #F4F7F5;
color: #222222;
}
and JS
particlesJS("particles-js",
{
"particles": {
"number": {
"value": 50,
"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": 3,
"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": 3,
"direction": "none",
"random": false,
"straight": false,
"out_mode": "out",
"bounce": false,
"attract": {
"enable": false,
"rotateX": 600,
"rotateY": 1200
}
}
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": {
"enable": false,
"mode": "repulse"
},
"onclick": {
"enable": false,
"mode": "push"
},
"resize": true
},
"modes": {
"grab": {
"distance": 527.4388051113614,
"line_linked": {
"opacity": 1
}
},
"bubble": {
"distance": 599.3622785356379,
"size": 63.93197637713472,
"duration": 5.354303021585032,
"opacity": 0.30367688779138985,
"speed": 3
},
"repulse": {
"distance": 271.7108996028225,
"duration": 0.4
},
"push": {
"particles_nb": 4
},
"remove": {
"particles_nb": 2
}
}
},
"retina_detect": true
});
Is this what you want ?
particlesJS("particles-js", { "particles": { "number": { "value": 50, "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": 3, "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": 3, "direction": "none", "random": false, "straight": false, "out_mode": "out", "bounce": false, "attract": { "enable": false, "rotateX": 600, "rotateY": 1200 } } }, "interactivity": { "detect_on": "canvas", "events": { "onhover": { "enable": false, "mode": "repulse" }, "onclick": { "enable": false, "mode": "push" }, "resize": true }, "modes": { "grab": { "distance": 527.4388051113614, "line_linked": { "opacity": 1 } }, "bubble": { "distance": 599.3622785356379, "size": 63.93197637713472, "duration": 5.354303021585032, "opacity": 0.30367688779138985, "speed": 3 }, "repulse": { "distance": 271.7108996028225, "duration": 0.4 }, "push": { "particles_nb": 4 }, "remove": { "particles_nb": 2 } } }, "retina_detect": true });
body { margin:0; } #particles-js { position:relative; width: 100%; height: 100vh; background-color: #222; background-repeat: no-repeat; background-size: cover; background-position: 50% 50%; } canvas { position: absolute; width: 100%; height: 100%; } .content { background:#000; height: 100vh; color: #fff; } .content h1 { margin-top:0; }
<div id="particles-js"> </div> <div class="content"> <h1>Content</h1> </div> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/particles.js/2.0.0/particles.min.js"></script>
Am Not good with js, but as for css, positioning two objects would be wrong simply because both of them can't take the entire space. I recommend u use absolute with relative of both relative, than position them using: left, right , top , bottom
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.