Skip to content

Commit ae4f4b0

Browse files
support multi canvas / multi particles-js on the same page (dom)
1 parent 7945e55 commit ae4f4b0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

particles.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
/* v1.1.1
77
/* ----------------------------------------------- */
88

9-
function launchParticlesJS(tag_id, params){
9+
var pJS = function(tag_id, params){
1010

1111
var canvas_el = document.querySelector('#'+tag_id+' > canvas');
1212

1313
/* particles.js variables with default values */
14-
window.pJS = {
14+
this.pJS = {
1515
canvas: {
1616
el: canvas_el,
1717
w: canvas_el.offsetWidth,
@@ -99,6 +99,8 @@ function launchParticlesJS(tag_id, params){
9999
}
100100
};
101101

102+
var pJS = this.pJS;
103+
102104
Object.deepExtend = function(destination, source) {
103105
for (var property in source) {
104106
if (source[property] && source[property].constructor &&
@@ -750,6 +752,8 @@ function hexToRgb(hex){
750752

751753
/* --- LAUNCH --- */
752754

755+
window.pJSDom = [];
756+
753757
window.particlesJS = function(tag_id, params){
754758

755759
/* no string id? so it's object params, and set the id with default id */
@@ -775,7 +779,7 @@ window.particlesJS = function(tag_id, params){
775779

776780
/* launch particle.js */
777781
if(canvas != null){
778-
launchParticlesJS(tag_id, params);
782+
pJSDom.push(new pJS(tag_id, params));
779783
}
780784

781785
};

0 commit comments

Comments
 (0)