Scripts2026年7月3日·1 分钟阅读

Typed.js — Animated Typing Effect for the Web

A JavaScript library that types out strings at a configurable speed, deletes them, and types new ones, creating a realistic typewriter effect for websites and landing pages.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 66/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Typed.js Overview
先审查命令
npx -y tokrepo@latest install d10fad07-7705-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

Introduction

Typed.js creates a realistic typewriter animation effect that types out text, pauses, deletes it, and cycles through an array of strings. It is widely used on marketing pages, portfolio sites, and developer landing pages to draw attention to key messages with engaging motion.

What Typed.js Does

  • Types out strings character by character at a configurable speed
  • Supports backspacing and cycling through multiple strings
  • Allows HTML tags and inline styling within typed content
  • Provides smart backspacing that only deletes differing suffixes
  • Offers shuffle mode to randomize the string display order

Architecture Overview

Typed.js uses a recursive setTimeout loop to append one character at a time to the target element's innerHTML or textContent. It tracks the current string index, character position, and direction (typing vs. deleting). When HTML mode is enabled, the parser detects opening and closing tags and inserts them atomically rather than character by character, preserving valid markup throughout the animation cycle.

Self-Hosting & Configuration

  • Install via npm, yarn, or include directly from a CDN
  • Pass an options object with strings, typeSpeed, and backSpeed
  • Use startDelay and backDelay to control pauses between cycles
  • Set contentType: 'html' to allow rich formatting in typed strings
  • Bind lifecycle callbacks like onComplete, preStringTyped, and onStringTyped

Key Features

  • Zero dependencies with a small footprint under 5 KB gzipped
  • Smart backspace that preserves common prefixes across strings
  • CSS cursor styling with configurable blink speed
  • Pause, resume, stop, and reset programmatic controls
  • Framework adapters available for React and Vue

Comparison with Similar Tools

  • Typewriter Effect (CSS-only) — pure CSS but limited to single strings; Typed.js cycles through multiple strings
  • TypeIt — similar feature set with a commercial license; Typed.js is MIT-licensed
  • Terminal-style CSS — static appearance only; Typed.js delivers real character-by-character animation
  • GSAP TextPlugin — part of a larger library; Typed.js is focused and standalone

FAQ

Q: Can I use HTML inside the typed strings? A: Yes. Set contentType: 'html' and include tags like <strong> or <span> in your strings array.

Q: How do I stop the animation after one loop? A: Set loop: false (the default) and the animation stops after typing all strings once.

Q: Does Typed.js work with React? A: Yes. Use a ref to the target element and initialize Typed in a useEffect hook, returning the destroy function for cleanup.

Q: Can I control typing speed per character? A: Use the caret notation ^1000 inside a string to insert a millisecond pause at that position.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产