Get started with tsparticles-interaction-external-attract CDN

MIT licensed

TS Particles plugin: Attracts particles to external objects or mouse.

Tags:
  • tsparticles
  • particles.js
  • particlesjs
  • particles
  • particle
  • canvas
  • jsparticles
  • xparticles
  • particles-js
  • particles-bg
  • particles-bg-vue
  • particles-ts
  • particles.ts
  • react-particles-js
  • react-particles.js
  • react-particles
  • react
  • reactjs
  • vue-particles
  • ngx-particles
  • angular-particles
  • particleground
  • vue
  • vuejs
  • preact
  • preactjs
  • jquery
  • angularjs
  • angular
  • typescript
  • javascript
  • animation
  • web
  • html5
  • web-design
  • webdesign
  • css
  • html
  • css3
  • animated
  • background
  • confetti
  • fireworks
  • fireworks-js
  • confetti-js
  • confettijs
  • fireworksjs
  • canvas-confetti

Stable version

Copied!

How to start using tsparticles-interaction-external-attract CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with tsparticles-interaction-external-attract CDN - cdnhub.io</title>
  <style>
    #tsparticles {
      height: 100vh;
      width: 100%;
    }
  </style>
</head>
<body>
  <div id="tsparticles"></div>
  <script src="https://cdn.jsdelivr.net/npm/worksans@4.2.0/worksans.min.css"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js"></script>
  <script src="https://cdn.cdnhub.io/tsparticles-interaction-external-attract/2.12.0/tsparticles.interaction.external.attract.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/tsparticles/r118/tsparticles.min.js"></script>

  <script>
    const particlesInit = async () => {
      await tsParticles.load('tsparticles', {
        backgroundMode: {
          enable: true,
          color: '#000000',
          opacity: 0.5
        },
        interactivity: {
          events: {
            onHover: {
              enable: true,
              mode: 'repulse'
            },
            onClick: {
              enable: true,
              mode: 'attract'
            },
            resize: true
          },
          modes: {
            attract: {
              distance: 100,
              duration: 0.5,
              ease: 'quint.out'
            }
          }
        },
        particles: {
          number: {
            value: 50,
            density: {
              enable: true,
              value_area: 800
            }
          },
          color: {
            value: '#ffffff'
          },
          shape: {
            type: 'circle'
          },
          size: {
            value: 5,
            random: true,
            anim: {
              enable: false,
              speed: 1,
              size_min: 0.1,
              sync: false
            }
          },
          opacity: {
            value: 0.5,
            random: true,
            anim: {
              enable: false,
              speed: 1,
              opacity_min: 0.1
            }
          }
        },
        interactivity: {
          detectsOn: 'canvas',
          zones: []
        },
        custom_properties: {
          number_of_attractors: 3
        }
      });

      const attractors = document.createElementNS('http://www.w3.org/2000/svg', 'g');
      attractors.setAttribute('id', 'attractors');
      document.querySelector('#tsparticles').appendChild(attractors);

      for (let i = 0; i < 3; i++) {
        const attractor = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
        attractor.setAttribute('cx', Math.floor(Math.random() * window.innerWidth));
        attractor.setAttribute('cy', Math.floor(Math.random() * window.innerHeight));
        attractor.setAttribute('r', Math.floor(Math.random() * 50) + 25);
        attractor.setAttribute('fill', '#ff0000');
        attractors.appendChild(attractor);
      }

      tsParticles.interaction.external.attract(document.querySelector('#tsparticles'), attractors);
    };

    window.addEventListener('DOMContentLoaded', particlesInit);
  </script>
</body>
</html>
Copied!
Copied!

All versions