2.0.3 • Published 11 months ago

text-particles.js v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

npm.io npm downloads ci npm.io

text-particles.js

text-particles.js is a lightweight TypeScript library for creating dynamic text particle effects using the Canvas API.

text-particles.js

Installation

npm install text-particles.js

or

yarn add text-particles.js

or

pnpm add text-particles.js

via CDN

https://cdn.jsdelivr.net/npm/text-particles.js/dist/index.min.js

Usage

React/Next.js (Pages Router)

import React, { useEffect, useRef } from "react";
import TextParticles from "text-particles.js";

const ParticleTextEffect: React.FC = () => {
  const canvasRef = useRef<HTMLCanvasElement>(null);

  useEffect(() => {
    if (canvasRef.current) {
      new TextParticles(canvasRef.current, {
        TEXT: "Your Text Here",
        FONT: {
          SIZE: 100,
        },
      });
    }
  }, []);

  return (
    <div style={{ width: "100%", height: "300px" }}>
      <canvas ref={canvasRef}></canvas>
    </div>
  );
};

export default ParticleTextEffect;

Next.js (App Router)

"use client";
import { useEffect, useRef } from "react";
import TextParticles from "text-particles.js";

const ParticleTextEffect = () => {
  const canvasRef = useRef<HTMLCanvasElement>(null);

  useEffect(() => {
    if (canvasRef.current) {
      new TextParticles(canvasRef.current, {
        TEXT: "Your Text Here",
        FONT: {
          SIZE: 100,
        },
      });
    }
  }, []);

  return (
    <div style={{ width: "100%", height: "300px" }}>
      <canvas ref={canvasRef}></canvas>
    </div>
  );
};

export default ParticleTextEffect;

Angular

import { Component, AfterViewInit, ElementRef, ViewChild } from '@angular/core';
import TextParticles from 'text-particles.js';

@Component({
  selector: 'app-particle-text',
  template: '<div #canvasContainer style="width: 100%; height: 300px;"><canvas #canvas></canvas></div>',
})
export class ParticleTextComponent implements AfterViewInit {
  @ViewChild('canvas') canvasRef!: ElementRef<HTMLCanvasElement>;

  ngAfterViewInit() {
    const canvas = this.canvasRef.nativeElement;
    new TextParticles(canvas, {
      TEXT: 'Your Text Here',
      FONT: {
          SIZE: 100,
        },
    });
  }
}

Svelte

<script>
  import { onMount } from 'svelte';
  import TextParticles from 'text-particles.js';

  let canvas;

  onMount(() => {
    new TextParticles(canvas, {
      TEXT: 'Your Text Here',
      FONT: {
          SIZE: 100,
        },
    });
  });
</script>

<div style="width: 100%; height: 300px;">
  <canvas bind:this={canvas}></canvas>
</div>

Vue.js

<template>
  <div style="width: 100%; height: 300px;">
    <canvas ref="canvas"></canvas>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted } from 'vue';
import TextParticles from 'text-particles.js';

export default defineComponent({
  name: 'ParticleTextEffect',
  setup() {
    onMounted(() => {
      const canvas = document.querySelector('canvas') as HTMLCanvasElement;
      new TextParticles(canvas, {
        TEXT: 'Your Text Here',
        FONT: {
          SIZE: 100,
        },
      });
    });
  }
});
</script>

Options

OptionDescriptionDefault
TEXTThe text to display."Text Particles"
FONTFont settings for the text.
STYLEFont style (e.g., "bold")."bold"
SIZEFont size in pixels.50
FAMILYFont family."Arial, sans-serif"
COLORThe color of the particles."#ff4f4f"
PARTICLE_SIZE_MINMinimum size of the particles.1
PARTICLE_SIZE_MAXMaximum size of the particles.3
HOVER_RADIUSRadius for hover interactions.30
CLICK_RADIUSRadius for click interactions.100
REPULSION_STRENGTHStrength of the repulsion effect.30
RETURN_SPEEDSpeed at which particles return to their original positions.10
INTERACTION_MODEInteraction mode, either "hover" or "click"."hover"

LICENSE

This project is licensed under the MIT License

2.0.3

11 months ago

2.0.2

12 months ago

2.0.1

12 months ago

2.0.0

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago