|
| 1 | +[](https://particles.js.org) |
| 2 | + |
| 3 | +# tsParticles External Cannon Interaction |
| 4 | + |
| 5 | +[](https://www.jsdelivr.com/package/npm/@tsparticles/interaction-external-cannon) |
| 6 | +[](https://www.npmjs.com/package/@tsparticles/interaction-external-cannon) |
| 7 | +[](https://www.npmjs.com/package/@tsparticles/interaction-external-cannon) [](https://github.com/sponsors/matteobruni) |
| 8 | + |
| 9 | +[tsParticles](https://github.com/tsparticles/tsparticles) interaction plugin for a particles cannon |
| 10 | +with the mouse/pointer. |
| 11 | + |
| 12 | +## How to use it |
| 13 | + |
| 14 | +### CDN / Vanilla JS / jQuery |
| 15 | + |
| 16 | +The CDN/Vanilla version JS has one required file in vanilla configuration: |
| 17 | + |
| 18 | +Including the `tsparticles.interaction.external.cannon.min.js` file will export the function to load the interaction |
| 19 | +plugin: |
| 20 | + |
| 21 | +```javascript |
| 22 | +loadExternalCannonInteraction; |
| 23 | +``` |
| 24 | + |
| 25 | +### Usage |
| 26 | + |
| 27 | +Once the scripts are loaded you can set up `tsParticles` and the interaction plugin like this: |
| 28 | + |
| 29 | +```javascript |
| 30 | +(async () => { |
| 31 | + await loadInteractivityPlugin(tsParticles); |
| 32 | + await loadExternalCannonInteraction(tsParticles); |
| 33 | + |
| 34 | + await tsParticles.load({ |
| 35 | + id: "tsparticles", |
| 36 | + options: { |
| 37 | + interactivity: { |
| 38 | + events: { |
| 39 | + onClick: { |
| 40 | + enable: true, |
| 41 | + mode: "cannon", |
| 42 | + }, |
| 43 | + }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + }); |
| 47 | +})(); |
| 48 | +``` |
| 49 | + |
| 50 | +### ESM / CommonJS |
| 51 | + |
| 52 | +This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this: |
| 53 | + |
| 54 | +```shell |
| 55 | +$ npm install @tsparticles/interaction-external-cannon |
| 56 | +``` |
| 57 | + |
| 58 | +or |
| 59 | + |
| 60 | +```shell |
| 61 | +$ yarn add @tsparticles/interaction-external-cannon |
| 62 | +``` |
| 63 | + |
| 64 | +Then you need to import it in the app, like this: |
| 65 | + |
| 66 | +```javascript |
| 67 | +const { tsParticles } = require("@tsparticles/engine"); |
| 68 | +const { loadInteractivityPlugin } = require("@tsparticles/plugin-interactivity"); |
| 69 | +const { loadExternalCannonInteraction } = require("@tsparticles/interaction-external-cannon"); |
| 70 | + |
| 71 | +(async () => { |
| 72 | + await loadInteractivityPlugin(tsParticles); |
| 73 | + await loadExternalCannonInteraction(tsParticles); |
| 74 | +})(); |
| 75 | +``` |
| 76 | + |
| 77 | +or |
| 78 | + |
| 79 | +```javascript |
| 80 | +import { tsParticles } from "@tsparticles/engine"; |
| 81 | +import { loadInteractivityPlugin } from "@tsparticles/plugin-interactivity"; |
| 82 | +import { loadExternalCannonInteraction } from "@tsparticles/interaction-external-cannon"; |
| 83 | + |
| 84 | +(async () => { |
| 85 | + await loadInteractivityPlugin(tsParticles); |
| 86 | + await loadExternalCannonInteraction(tsParticles); |
| 87 | +})(); |
| 88 | +``` |
0 commit comments