Home

Awesome

malarkey npm Version Build Status Coverage Status

Simulate a typewriter effect in vanilla JavaScript.

Usage

Editable demo (CodePen)

<div class="typewriter"></div>
const malarkey = require('malarkey')

const element = document.querySelector('.typewriter')
function callback (text) {
  element.textContent = text
}
const options = {
  typeSpeed: 50,
  deleteSpeed: 50,
  pauseDuration: 2000,
  repeat: true
}
malarkey(callback, options)
  .type('Say hello')
  .pause()
  .delete()
  .type('Wave goodbye')
  .pause()
  .delete()

API

const malarkey = require('malarkey')

const m = malarkey(callback [, options])

Initialise the typewriter effect with the given optional options settings.

m.type(string [, options])

Type the given string, one character at a time.

m.delete([characterCount, options])

Delete the specified number of characters, one character at a time.

m.pause([options])

Do nothing for some duration.

m.clear()

Immediately clear all characters that were typed.

m.call(fn)

Call the given fn function.

m.triggerStop([fn])

Stops the sequence. Calls the given fn function when the sequence has been stopped.

m.triggerResume()

Resume the sequence. Has no effect if the sequence is already running.

m.isStopped()

Returns true if the sequence is currently stopped, else returns false.

Installation

Install via yarn:

$ yarn add malarkey

Or npm:

$ npm install --save malarkey

License

MIT