Tsparticles: How to change particle options on the fly?

Created on 26 Mar 2020  路  2Comments  路  Source: matteobruni/tsparticles

Hi, thank you for this, I've just tried switching to this from the original version and I can say so far so good.

However I can't seem to find a way to change the config options on the fly. In the original I can do like this:

const pJS = global.pJSDom[0].pJS;

pJS.particles.color.value = currentTheme.color;
pJS.particles.line_linked.color = currentTheme.color;
pJS.particles.shape.stroke.color = currentTheme.bgColor;
pJS.fn.particlesRefresh();

How can I achieve the same thing with this?

question

Most helpful comment

Hi @tkhquang

I changed the old undocumented methods a little bit, to make them clearer.

All the options are now under the options property of the main container and the main container has a refresh() method

const particles = tsParticles.domItem(0);
const options = particles.options;

options.particles.color.value = currentTheme.color;
options.lineLinked.color = currentTheme.color;
options.particles.shape.stroke.color = currentTheme.bgColor;

particles.refresh();

All 2 comments

Hi @tkhquang

I changed the old undocumented methods a little bit, to make them clearer.

All the options are now under the options property of the main container and the main container has a refresh() method

const particles = tsParticles.domItem(0);
const options = particles.options;

options.particles.color.value = currentTheme.color;
options.lineLinked.color = currentTheme.color;
options.particles.shape.stroke.color = currentTheme.bgColor;

particles.refresh();

Thank you @matteobruni , I got it working but I got to change options.lineLinked.color to options.particles.lineLinked.color.

Was this page helpful?
0 / 5 - 0 ratings