particles.js
particles.js copied to clipboard
Stopping the Animation from javascript
Hi, Is there any chance to stop the animation using javascript, after it started running? I tried to find the Code inside your Examples GUI, but was unable to find how you disable the animation afterwards..
Hey @XRyu ,
You can do it by this way:
pJSDom[0].pJS.particles.move.enable = false;
To restart:
pJSDom[0].pJS.particles.move.enable = true;
pJSDom[0].pJS.fn.particlesRefresh();
If you want to destroy it, see https://github.com/VincentGarreau/particles.js/issues/63#issuecomment-242977446
Is there a similar method for turning interactivity on and off?
pJSDom[0].pJS.interactivity.events.onclick["enable"] = false;
Is it possible to pause the movement, and then re-enable it without refreshing?
I want to pause an animation while the user is scrolling.
@VincentGarreau, thanks so much!
Is it possible to pause the movement, and then re-enable it without refreshing?
I want to pause an animation while the user is scrolling.
pause() {
this._tempFn = this.pJS.fn.vendors.draw
window.pJSDom[0].pJS.fn.vendors.draw = () => {
}
}
play() {
window.pJSDom[0].pJS.fn.vendors.draw = this._tempFn
window.pJSDom[0].pJS.fn.vendors.draw()
}
Is it possible to pause the movement, and then re-enable it without refreshing? I want to pause an animation while the user is scrolling.
pause() { this._tempFn = this.pJS.fn.vendors.draw window.pJSDom[0].pJS.fn.vendors.draw = () => { } } play() { window.pJSDom[0].pJS.fn.vendors.draw = this._tempFn window.pJSDom[0].pJS.fn.vendors.draw() }
It worked for me with corrected second line:
pause() {
this._tempFn = window.pJSDom[0].pJS.fn.vendors.draw;
window.pJSDom[0].pJS.fn.vendors.draw = () => {};
}
play() {
window.pJSDom[0].pJS.fn.vendors.draw = this._tempFn;
window.pJSDom[0].pJS.fn.vendors.draw();
}