Skip to content

Methods

ParticleText.js instances expose several methods for controlling animation and querying state. Access these methods through the object returned by initParticleJS().

const particle = initParticleJS('#canvas', { colors: ['#695aa6'] });
// Available methods:
particle.start Animation();
particle.forceRequestAnimationFrame();
particle.getCurrentBreakpoint();

Manually starts the animation. Use this when autoAnimate is set to false.

particle.startAnimation()

None

undefined

// Initialize without auto-start
const particle = initParticleJS('#canvas', {
colors: ['#695aa6'],
autoAnimate: false // Don't start automatically
});
// Start animation when user clicks button
document.getElementById('startBtn').addEventListener('click', () => {
particle.startAnimation();
console.log('Animation started!');
});
  • Calling startAnimation() multiple times has no effect after the first call
  • Animation state is tracked via isAnimating property
  • Once started, animation cannot be stopped (by design)
const particle = initParticleJS('#canvas', {
colors: ['#695aa6'],
autoAnimate: false
});
// Start after 2 seconds
setTimeout(() => {
particle.startAnimation();
}, 2000);
const particle = initParticleJS('#hero-canvas', {
text: 'Welcome',
colors: ['#695aa6'],
autoAnimate: false
});
// Start when page is visible
document.addEventListener('DOMContentLoaded', () => {
if (document.visibilityState === 'visible') {
particle.startAnimation();
}
});

Forces an immediate single-frame render of the animation. Useful for debugging or manual frame-by-frame control.

particle.forceRequestAnimationFrame()

None

undefined

const particle = initParticleJS('#canvas', {
colors: ['#695aa6'],
autoAnimate: false // Manual control
});
// Render single frame
particle.forceRequestAnimationFrame();
// Render another frame
particle.forceRequestAnimationFrame();
  • This renders only ONE frame
  • Primarily for debugging and testing
  • Does not start continuous animation
  • Can be called before or after startAnimation()
const particle = initParticleJS('#canvas', {
colors: ['#695aa6'],
autoAnimate: false
});
let frame = 0;
// Render frame-by-frame
document.getElementById('nextFrame').addEventListener('click', () => {
particle.forceRequestAnimationFrame();
console.log(`Rendered frame ${++frame}`);
});

Returns the current responsive breakpoint based on viewport width. Can be overridden for custom breakpoint logic.

particle.getCurrentBreakpoint()

None

String - Current breakpoint key

Possible values: 'xxxs', 'xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl', 'xxxl'

const particle = initParticleJS('#canvas', {
colors: ['#695aa6']
});
// Check current breakpoint
const breakpoint = particle.getCurrentBreakpoint();
console.log(breakpoint); // e.g., 'lg' on desktop
// Use in conditional logic
if (breakpoint === 'xs' || breakpoint === 'xxs') {
console.log('Mobile device detected');
}
BreakpointWidth Range
xxxs0px - 320px
xxs320px - 375px
xs375px - 768px
sm768px - 1024px
md1024px - 1440px
lg1440px - 2560px
xl2560px - 3440px
xxl3440px - 3840px
xxxl3840px+
const particle = initParticleJS('#canvas', {
colors: ['#695aa6']
});
// Adjust behavior based on breakpoint
const bp = particle.getCurrentBreakpoint();
if (bp === 'xs' || bp === 'xxs' || bp === 'xxxs') {
console.log('Optimizing for mobile');
// Could adjust particle count, etc.
}

You can override this method to implement custom breakpoint logic:

const particle = initParticleJS('#canvas', {
colors: ['#695aa6']
});
// Override with custom logic
particle.getCurrentBreakpoint = function() {
const width = window.innerWidth;
if (width < 600) return 'mobile';
if (width < 1200) return 'tablet';
return 'desktop';
};
console.log(particle.getCurrentBreakpoint()); // 'mobile', 'tablet', or 'desktop'

Note: When overriding, ensure your custom breakpoints match those used in particleRadius and explosionRadius configurations.


Methods can be called sequentially, but they don’t return the instance (no chaining):

const particle = initParticleJS('#canvas', {
colors: ['#695aa6'],
autoAnimate: false
});
// Call methods
particle.startAnimation();
particle.forceRequestAnimationFrame(); // Not chained
const bp = particle.getCurrentBreakpoint();
console.log(bp);