tsParticles is compatible with particles.js, and migration can be done in a few steps.
particles.min.js with tsparticles.min.jsparticles-js -> tsparticles)particlesJS(...) APIs with tsParticles.load(...)snake_case -> camelCase)<script src="particles.min.js"></script>
becomes:
<script src="tsparticles.min.js"></script>
If you had custom CSS on the canvas:
.particles-js-canvas-element {
/* custom CSS */
}
becomes:
.tsparticles-canvas-element {
/* custom CSS */
}
| particles.js | tsParticles |
|---|---|
particlesJS("id", options) |
tsParticles.load({ id: "id", options }) |
particlesJS.load("id", "path", callback) |
tsParticles.loadJSON("id", "path").then(...) |
Before:
particlesJS.load("particles-js", "assets/particles.json", () => {
console.log("callback - particles.js config loaded");
});
After:
tsParticles.loadJSON("tsparticles", "assets/particles.json").then((container) => {
console.log("callback - tsParticles config loaded", container);
});
Or with inline options:
tsParticles.load({
id: "tsparticles",
options: {
/* options */
},
});
Note: loadJSON does not use callback as a third parameter; use then(...).
Many legacy options still work, but updating them is recommended:
line_linked -> linksretina_detect -> detectRetinasnake_case -> camelCaseIf you see console warnings, use them as a guide to update your configuration file.
loadJSON with a callback argument instead of then(...)