A simple yet powerful native javascript plugin for a cool typewriter effect.

Overview

TypewriterJS v2

CircleCI

NPM Repository JSFiddle Example Emoji Example

CDN

You can use the CDN version of this plugin for fast and easy setup.

<script src="https://unpkg.com/typewriter-effect@latest/dist/core.js"></script>

Core

This include the core typewriter library, which can be used directly through the API.

See examples in the 'examples' folder.

import Typewriter from 'typewriter-effect/dist/core';

new Typewriter('#typewriter', {
  strings: ['Hello', 'World'],
  autoStart: true,
});

Options

Name Type Default value Description
strings String or Array null Strings to type out when using autoStart option
cursor String Pipe character String value to use as the cursor.
delay 'natural' or Number 'natural' The delay between each key when typing.
deleteSpeed 'natural' or Number 'natural' The delay between deleting each character.
loop Boolean false Whether to keep looping or not.
autoStart Boolean false Whether to autostart typing strings or not. You are required to provide strings option.
pauseFor Number 1500 The pause duration after a string is typed when using autostart mode
devMode Boolean false Whether or not to display console logs.
skipAddStyles Boolean Skip adding default typewriter css styles.
wrapperClassName String 'Typewriter__wrapper' Class name for the wrapper element.
cursorClassName String 'Typewriter__cursor' Class name for the cursor element.
stringSplitter Function String splitter function, can be used to split emoji's
onCreateTextNode Function null Callback function to replace the internal method which creates a text node for the character before adding it to the DOM. If you return null, then it will not add anything to the DOM and so it is up to you to handle it.
onRemoveNode Function null Callback function when a node is about to be removed. First param will be an object { node: HTMLNode, charater: string }

Methods

All methods can be chained together.

Name Params Description
start - Start the typewriter effect.
stop - Stop the typewriter effect.
pauseFor ms Time to pause for in milliseconds Pause for milliseconds
typeString string String to type out, it can contain HTML tags Type out a string using the typewriter effect.
pasteString string String to paste out, it can contain HTML tags Paste out a string.
deleteAll speed Speed to delete all visibles nodes, can be number or 'natural' Delete everything that is visible inside of the typewriter wrapper element.
deleteChars amount Number of characters Delete and amount of characters, starting at the end of the visible string.
callFunction cb Callback, thisArg this Object to bind to the callback function Call a callback function. The first parameter to the callback elements which contains all DOM nodes used in the typewriter effect.
changeDeleteSpeed speed Number or 'natural' The speed at which to delete the characters, lower number is faster.
changeDelay delay Number or 'natural' Change the delay when typing out each character

Examples

Basic example

var app = document.getElementById('app');

var typewriter = new Typewriter(app, {
  loop: true,
  delay: 75,
});

typewriter
  .pauseFor(2500)
  .typeString('A simple yet powerful native javascript')
  .pauseFor(300)
  .deleteChars(10)
  .typeString('<strong>JS</strong> plugin for a cool typewriter effect and ')
  .typeString('<strong>only <span style="color: #27ae60;">5kb</span> Gzipped!</strong>')
  .pauseFor(1000)
  .start();

Custom text node creator using callback

var app = document.getElementById('app');

var customNodeCreator = function(character) {
  return document.createTextNode(character);
}

var typewriter = new Typewriter(app, {
  loop: true,
  delay: 75,
  onCreateTextNode: customNodeCreator,
});

typewriter
  .typeString('A simple yet powerful native javascript')
  .pauseFor(300)
  .start();

Custom handling text insert using input placeholder

var input = document.getElementById('input')

var customNodeCreator = function(character) {
  // Add character to input placeholder
  input.placeholder = input.placeholder + character;

  // Return null to skip internal adding of dom node
  return null;
}

var onRemoveNode = function({ character }) {
  if(input.placeholder) {
    // Remove last character from input placeholder
    input.placeholder = input.placeholder.slice(0, -1)
  }
}

var typewriter = new Typewriter(null, {
  loop: true,
  delay: 75,
  onCreateTextNode: customNodeCreator,
  onRemoveNode: onRemoveNode,
});

typewriter
  .typeString('A simple yet powerful native javascript')
  .pauseFor(300)
  .start();

React

This includes a React component which can be used within your project. You can pass in a onInit function which will be called with the instance of the typewriter so you can use the typewriter core API.

import Typewriter from 'typewriter-effect';

<Typewriter
  onInit={(typewriter) => {
    typewriter.typeString('Hello World!')
      .callFunction(() => {
        console.log('String typed out!');
      })
      .pauseFor(2500)
      .deleteAll()
      .callFunction(() => {
        console.log('All strings were deleted');
      })
      .start();
  }}
/>

Alternatively you can also pass in options to use auto play and looping for example:

import Typewriter from 'typewriter-effect';

<Typewriter
  options={{
    strings: ['Hello', 'World'],
    autoStart: true,
    loop: true,
  }}
/>
Comments
  • deleteAll not working in Internet Explorer

    deleteAll not working in Internet Explorer

    I have found an issue with deleteAll in Internet Explorer 11. When I apply deleteAll(), it's just ignored and the next string is just appended. In the developer tools, there is an error like Object doesn't support property or method 'remove'. I could even reproduce it in this example: https://jsfiddle.net/mv612vrf/1702

    Do you have an idea how to solve it?

    opened by dtslvr 9
  • Time between the loops keep increasing.

    Time between the loops keep increasing.

    I am trying to write a string followed by erasing it and than writing it again in a loop. However, I have noticed the time delay between each individual loops keep increasing. The first loop takes almost no seconds. The second loops takes a bit longer, the third takes even more longer and so on... Here is the code:

      new Typewriter(app, { loop: true })
        .typeString("Hello World!")
        .pauseFor(250)
        .start();
    

    I have managed to work around this by exploiting the callback feature. Here is the code:

      (function callBack() {
        new Typewriter(app)
          .typeString("Hello World!")
          .pauseFor(250)
          .deleteAll()
          .start()
          .callFunction(callBack);
      })();
    
    

    I hope we can track down the root issue for this.

    Updated: Following is the cdn I am using:

    opened by hrghauri 8
  • onMouseOver Effect

    onMouseOver Effect

    Hi guys,

    Firstly like to say thanks for this awesome script. I am a total programming noobie but I am trying to achieve a certain effect with the typewriter where you hover over an element and will write something out.

    I have got it working for the most part where it will make a new instance using the js mouseenter event but its susceptible to glitching and spazzing out when it is spammed. It will just keep firing a new instance and pile up tying gibberish (due to delays, combined strings etc). I have attempted to set a timerOut/Clear on it but couldn't get it going.

    I realise this isn't issue directly with the script, just wondering if there is a better way to go about it (eg argument to kill/restart current typewriter) again sorry I am a total noob learning as I go. Thanks in advance!

    opened by calebarchie 8
  • Turn off blinking cursor at the end

    Turn off blinking cursor at the end

    Hi, I am currently using the Typewriterjs for animated header. I was wondering if there is a way to remove or in the least pause the blinking cursor once it finishes playing. Tried using the changeSetting method but that doesn't seem to work either.

    Am I doing something wrong?

     var typewriter = new Typewriter(app, {
         loop: false,
         blinkSpeed: 35
     });
    
    
     typewriter.typeString('Testing Testing Testing')
         .pauseFor(3500)
         .changeSettings({ "animateCursor": false })
         .start();
    

    Thank you in advance

    opened by yuehkchou 7
  • [Feature Request] Add Support for Flushing Queue

    [Feature Request] Add Support for Flushing Queue

    Hi, thanks for this plugin!

    I’m currently using it in a project of mine where the strings to be typed can change before the animation has finished. The way this plugin works now, it finishes the original string, then executes the scheduled "deleteAll" and then types the new string. It would be great if you could add a method to "flush" all changes out of the queue, allowing the "deleteAll" to be handled as soon as it is requested and not after the animation has run.

    I hope it’s clear what I mean. Cheers and thanks again!

    opened by amxmln 6
  • Possible callbacks

    Possible callbacks

    Would be great to have the Chance of registering callbacks in a fluent manner alter each string is written for example. Would be great for guided walk throughs on a website.

    Considering it making async also with promises.

    opened by nhaberl 6
  • Tags will not diplay

    Tags will not diplay

    I tried adding the
    tag and it didn't work, then I tried using the strong tag and that failed. I am unsure whether its my fault or it's the code which is facing errors.

    Example: .typeString('and
    this is my Portfolio')

    opened by Airo1011 5
  • This package breaks a

    This package breaks a "Next.js" application

    So, here's the situation ...

    While the application is running in development mode and installing this package via another terminal window, it works great, exactly like you want it.

    However, once you stop the server and try to "npm run dev" once again, it breaks the app, and it gives this error ...

    image

    I tried this multiple times just to be sure, with every time completely deleting the "node_modules" folder and starting fresh.

    opened by Shaker-Hamdi 5
  • string option does not work when array is passed as props

    string option does not work when array is passed as props

    Working `<Typewriter options={{ strings: [ "test1","test2","test3" ], autoStart: true, loop: true,

          }}/>`
    

    Not Working ` <Typewriter options={{ strings: this.props.typewriter, autoStart: true, loop: true,

          }}/>`
    
    opened by carljustineoyales 4
  • Static text infront of the typeString

    Static text infront of the typeString

    Is it possible to have a static text variable which will not be deleted? I couldn't find any examples and simply prepending a <span> my static text </span> results in a typing animation which starts from the right-to-left instead of the usual left-to-right.

    See this example - https://www.tmeyer.info

    opened by cirquit 4
  • Issues in IE11

    Issues in IE11

    Your project is still having issues on Internet explorer 11, "Unable to get property 'removeChild' of undefined or null reference" I've tested one of you're examples and it's also not working on IE11 (chatbot example)

    opened by pierrebonny 4
  • Bump json5 from 2.2.1 to 2.2.3

    Bump json5 from 2.2.1 to 2.2.3

    Bumps json5 from 2.2.1 to 2.2.3.

    Release notes

    Sourced from json5's releases.

    v2.2.3

    v2.2.2

    • Fix: Properties with the name __proto__ are added to objects and arrays. (#199) This also fixes a prototype pollution vulnerability reported by Jonathan Gregson! (#295).
    Changelog

    Sourced from json5's changelog.

    v2.2.3 [code, diff]

    v2.2.2 [code, diff]

    • Fix: Properties with the name __proto__ are added to objects and arrays. (#199) This also fixes a prototype pollution vulnerability reported by Jonathan Gregson! (#295).
    Commits
    • c3a7524 2.2.3
    • 94fd06d docs: update CHANGELOG for v2.2.3
    • 3b8cebf docs(security): use GitHub security advisories
    • f0fd9e1 docs: publish a security policy
    • 6a91a05 docs(template): bug -> bug report
    • 14f8cb1 2.2.2
    • 10cc7ca docs: update CHANGELOG for v2.2.2
    • 7774c10 fix: add proto to objects and arrays
    • edde30a Readme: slight tweak to intro
    • 97286f8 Improve example in readme
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Pass data attributes to the span element created by the typewriter component

    Pass data attributes to the span element created by the typewriter component

    Hi,

    I'm currently using locomotive scroll and in order to give it's effect to an element, the element has to be given data attributes such as "data-scroll", "data-scroll-direction"... Looking at the documentation it doesen't seem that there is a way to pass data attributes to the span element created by the typewriter effect

    image

    opened by Fedinjo 0
  • Unhandled Runtime Error

    Unhandled Runtime Error

    Conversation

    When I use the <TypeWriter /> react component in the NextJS project, following this instruction(the second one), the website showed me an error window below.

    The Error Window

    Unhandled Runtime Error
    Error: Hydration failed because the initial UI does not match what was rendered on the server.
    
    See more info here: https://nextjs.org/docs/messages/react-hydration-error
    
    Call Stack
    throwOnHydrationMismatch
    node_modules/react-dom/cjs/react-dom.development.js (12507:0)
    tryToClaimNextHydratableInstance
    node_modules/react-dom/cjs/react-dom.development.js (12520:0)
    updateHostComponent
    node_modules/react-dom/cjs/react-dom.development.js (19902:0)
    beginWork
    node_modules/react-dom/cjs/react-dom.development.js (21618:0)
    HTMLUnknownElement.callCallback
    node_modules/react-dom/cjs/react-dom.development.js (4164:0)
    Object.invokeGuardedCallbackDev
    node_modules/react-dom/cjs/react-dom.development.js (4213:0)
    invokeGuardedCallback
    node_modules/react-dom/cjs/react-dom.development.js (4277:0)
    beginWork$1
    node_modules/react-dom/cjs/react-dom.development.js (27451:0)
    performUnitOfWork
    node_modules/react-dom/cjs/react-dom.development.js (26557:0)
    workLoopSync
    node_modules/react-dom/cjs/react-dom.development.js (26466:0)
    renderRootSync
    node_modules/react-dom/cjs/react-dom.development.js (26434:0)
    performConcurrentWorkOnRoot
    node_modules/react-dom/cjs/react-dom.development.js (25738:0)
    workLoop
    node_modules/react-dom/node_modules/scheduler/cjs/scheduler.development.js (266:0)
    flushWork
    node_modules/react-dom/node_modules/scheduler/cjs/scheduler.development.js (239:0)
    MessagePort.performWorkUntilDeadline
    node_modules/react-dom/node_modules/scheduler/cjs/scheduler.development.js (533:0)
    

    Versions

    • NextJS version: 13.0.2
    • TypewriterJS version: 2.19.0

    The other problems

    Also, as I typed <TypeWriter, the suggestion showed the <TypewriterClass and <TypewriterComponent components, instead of the <TypeWriter> component that the suggestions should show.

    opened by cattynip 2
  • stop() doesn't work as expected (or not at all)

    stop() doesn't work as expected (or not at all)

    Hi, I'm trying to use stop() to interrupt the typewriter effect so it can move immediately into deleteAll() which I put after stop(). However, either stop() doesn't work as expected or it's not working at all because typewriter continues to type out the rest of the text then moves into deleteAll() as if stop() was never even there. Here's an example:

    let typeWriter = new Typewriter(tabContent, {
        loop: false,
        delay: 25,
        deleteSpeed: 15,
        cursor: '',
    });
    
    function interrupt() {
        typeWriter.stop();
        typeWriter.deleteAll(15);
        typeWriter.typeString("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    }
    
    typeWriter.typeString("123456789123456789123456789123456789123456789123456789123456789123456789123456789");
    setTimeout(function() { interrupt(); }, 1000);
    

    Is this unintended, user-error, or is the stop() explanation missing something?

    opened by HunterAhlquist 0
  • core.js:1 Uncaught TypeError:

    core.js:1 Uncaught TypeError:

    Please help me with this error : b.state.elements.container.appendChild is not a function at n.setupWrapperElement (core.js:1:5364) at n.value (core.js:1:11769) at new n (core.js:1:11697)

    opened by jeanpauljoel09 0
  • TypeError: Super expression must either be null or a function On Nextjs 13

    TypeError: Super expression must either be null or a function On Nextjs 13

    Getting above error by using simple example given.

    import Typewriter from "typewriter-effect";

    <Typewriter onInit={(typewriter) => { typewriter .typeString("Hello World!") .callFunction(() => { console.log("String typed out!"); }) .pauseFor(2500) .deleteAll() .callFunction(() => { console.log("All strings were deleted"); }) .start(); }} />

    opened by logivity 1
Cool and powerful effect to select fields. Javascript vanilla and ~2kb gzipped

pickout Cool and powerful effect to select fields. Javascript vanilla and ~2kb gzipped. DEMO PAGE For syntax of the previous version click here How to

Alan Ktquez 89 Sep 20, 2022
:keyboard: Simulate a typewriter effect in vanilla JavaScript.

malarkey Simulate a typewriter effect in vanilla JavaScript. Flexible API allowing granular control Option to repeat the sequence indefinitely Allows

Yuan Qing Lim 237 Nov 18, 2022
The typewriter effect

#No documentation yet! (feel free to write a bit about it) Download Get the raw script, download the complete package or fork it on GitHub. Support @y

Yannick Albert 27 Oct 7, 2020
A phaser helper for the typewriter effect

Phaser-typewriter A typewriter effect wrapper for Phaser.io Javascript library Initialize the typewriter anywhere in your game var typewriter = new Ty

Michael Dobekidis 39 Jul 27, 2022
A basic Typewriter effect.

Remotion video A basic Typewriter template. video.mp4 Commands Install Dependencies npm i Start Preview npm start Render video npm run build Upgrade R

Remotion 14 Dec 6, 2022
Warp drive is a lightweight jQuery plugin that helps you create a cool, interactive, configurable, HTML5 canvas based warp drive/starfield effect.

Warp drive jQuery plugin (jquery-warpdrive-plugin) Preview Description Warp drive is a lightweight jQuery plugin that helps you create a cool, interac

Niklas 51 Nov 15, 2022
"shuffle-text" is JavaScript text effect library such as cool legacy of Flash.

ShuffleText This is the JavaScript library for text effect such as Flash contents. Setup Script Install <script src="shuffle-text.js"></script> NPM In

Yasunobu Ikeda 96 Dec 24, 2022
Cool 2D dissolve effect generator

Dissolve Cool 2D dissolve effect generator (demo) This module exposes a generator for generating pseudorandom points over a 2D integer grid. The gener

Travis Fischer 13 Apr 15, 2021
magneticHover lets you trigger hover effect on the element when the cursor is near it, but not over it yet

magneticHover magneticHover lets you trigger hover effect on the element when the cursor is near it, but not over it yet. Examples https://codesandbox

Halo Lab 35 Nov 30, 2022
⌨️ Lightweight $.Hypertext.Typewriter

⚠️ iOS 13.3 note (April 2020) beep[:true] freezes the typewriter, read more: issue #11 Nice features ?? full HTML support beep-beep Hypertypin' Markup

Benjamin Lips 309 Dec 22, 2022
Liquideffect - Javascript Library for creating liquid effect on image and RGB effect on mouse direction.

LiquidEffect Javascript Library for creating liquid effect on image and RGB effect on mouse direction. Demo https://liquideffect.netlify.app/ Dependen

Rohail 8 May 6, 2022
A subtle tilt effect for images. The idea is to move and rotate semi-transparent copies with the same background image in order to create a subtle motion or depth effect.

Image Tilt Effect A subtle tilt effect for images. The idea is to move and rotate semi-transparent copies with the same background image in order to c

Codrops 571 Nov 21, 2022
KenBurns Image Effect for React Native Applications

react-native-kenburns-view KenBurns Image Effect for React Native. Based on Image Component Image Component. Version: 4.1.0 Tested on React Native 0.6

Nimila Hiranya Samarasinghe 58 Sep 3, 2022
Simple jQuery plugin for 3d Hover effect

jQuery Hover3d jQuery Hover3d is a simple hover script for creating 3d hover effect. It was my experiment on exploring CSS3 3d transform back in 2015

Rian Ariona 333 Jan 4, 2023
imagesLoaded - JavaScript is all like "You images done yet or what?"

imagesLoaded JavaScript is all like "You images done yet or what?" imagesloaded.desandro.com Detect when images have been loaded.

David DeSandro 8.8k Dec 29, 2022
Cool tips to design UI/UX on Leaflet maps.

Map Effects 100 Map Effects 100 has cool tips to design UI/UX on your Map. Map? Leaflet Quick Start git clone https://github.com/muxlab/map-effects-10

MUX Lab 187 Sep 21, 2022
Create cool animated SVG spinners, loaders and other looped animations in seconds

SVG Circus SVG Circus enables you to create cool animated SVG spinners, loaders and other looped animations in seconds. Developing To run a local SVG

Alex Kaul 301 Dec 24, 2022
Animated images that are superficially attractive and entertaining but intellectually undemanding. Cool as all hell though!

MMM-EyeCandy Animated images that are superficially attractive and entertaining but intellectually undemanding. Add some EyeCandy to your mirror. Some

Mykle 36 Dec 28, 2022
Animatelo is a bunch of cool, fun, and cross-browser animations for you to use in your projects. This is a porting to Web Animation API of the fabulous animate.css project.

Animatelo Just-add-water Web Animations Animatelo is a bunch of cool, fun, and cross-browser animations for you to use in your projects. Great for emp

GibboK 477 Nov 12, 2022