css 如何在一个页面中多次使用particles.js?

2nbm6dog  于 2023-01-03  发布在  其他
关注(0)|答案(3)|浏览(158)

我想知道如何在一个页面中添加多个particles.js?看起来每页只能添加一次。但是我想使用多个particles.js,比如在两个单独的div中。我该怎么做呢?我只能添加一次,但是在另一个div中似乎不能再添加一次。
下面是该插件的链接-https://github.com/VincentGarreau/particles.js/
谢谢你的时间。

var canvas_el = document.querySelector('#'+tag_id+' > .particles-js-canvas-el');
ruarlubt

ruarlubt1#

看看这个:http://codepen.io/anon/pen/avzPGm.

<div id="particles-js"></div>
<div id="particles-js2"></div>

然后:

particlesJS("particles-js", {...});
particlesJS("particles-js2", {...});

调用particleJS两次,每个元素一次。

ilmyapht

ilmyapht2#

看看这个https://codepen.io/ngocquydhtn/pen/VwePzmL
我的代码:
超文本:

<div id="particle-container" class="particle-class"></div>
<div id="particle-container2" class="particle-class"></div>
<div id="particle-container3" class="particle-class"></div>
<div id="particle-container4" class="particle-class"></div>
<div id="particle-container5" class="particle-class"></div>

联森:

jQuery(document).ready(function($) {
  $(".particle-class").each(function() {
    particlesJS($(this).attr('id'), {
    "particles": {
      "number": {
        "value": 80,
        "density": {
          "enable": true,
          "value_area": 800
        }
      },
      "color": {
        "value": "random"
      },
      "shape": {
        "type": "circle",
        "stroke": {
          "width": 0,
          "color": "random"
        },
        "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": 10,
        "random": true,
        "anim": {
          "enable": false,
          "speed": 40,
          "size_min": 2,
          "sync": false
        }
      },
      "line_linked": {
        "enable": false,
        "distance": 150,
        "color": "#ff6d34",
        "opacity": 0.4,
        "width": 1
      },
      "move": {
        "enable": true,
        "speed": 2,
        "direction": "none",
        "random": true,
        "straight": false,
        "out_mode": "out",
        "bounce": false,
        "attract": {
          "enable": false,
          "rotateX": 600,
          "rotateY": 1200
        }
      }
    },
    "interactivity": {
      "detect_on": "canvas",
      "events": {
        "onhover": {
          "enable": true,
          "mode": "grab"
        },
        "onclick": {
          "enable": false,
          "mode": "push"
        },
        "resize": true
      },
      "modes": {
        "grab": {
          "distance": 150,
          "line_linked": {
            "opacity": 1
          }
        },
        "bubble": {
          "distance": 400,
          "size": 40,
          "duration": 2,
          "opacity": 8,
          "speed": 3
        },
        "repulse": {
          "distance": 200,
          "duration": 0.4
        },
        "push": {
          "particles_nb": 4
        },
        "remove": {
          "particles_nb": 2
        }
      }
    },
    "retina_detect": true
  });

});
});
wko9yo5t

wko9yo5t3#

香草味JS
超文本:

<div id="particles-js"></div>
<div id="particles-js2"></div>
<div id="particles-js3"></div>

联森:

const particles_settings = {settings of the particles}
const particles_duplicity = ['particles-js', 'particles-js2', 'particles-js3']
    
 particles_duplicity.forEach(function(element) {
   particlesJS(element, particles_settings)
 })

相关问题